Bài viết này sẽ hướng dẫn các bạn cách thêm file icon hoặc image vào resource của project, nội dung gồm 3 phần sau:
1. Add/Import image/icon vào project
#1/3. Trong Solution Explorer > Right-click lên project > Properties/プロパティ(R)

Solution Explore > Right-click project > Properties
#2/3. Resources/リソース > Add Resource/リソースの追加(R) > Add Existing File…/存在ファイルの追加(E)…

Resources > Add Resource > Add Existing File…
#3/3. Browser đến file muốn import rồi click Open(O)/開く(O) (Để hiện tất cả các file image/icon thì chọn All Files(*.*)/すべてのファイル(*.*))

Sau khi chọn file xong, click Open
2. Thay đổi thuộc tính của file icon/image
#1/2. Right-click lên image/icon vừa được import vào project ở bước 1. > Properties/プロパティ(R)

Right-click image/icon > Properties
#2/2. Chỉnh sửa giá trị ở thuộc tính Build Action/ビルド アクション: Chuyển từ “None/なし hoặc Content/コンテンツ” sang “Embedded Resource/理め込まれたリソース”

Build Action > Embedded Resource
3. Cách sử dụng
#1/3. Cú pháp:
ProjectName・Namespace(DLL名).fileName.extension
#2/3. Ví dụ:
TenFileDllCuaProject.iconSample.ico
TenFileDllCuaProject.imageSample.png
#3/3. Demo:
Dim iconStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream( "TenFileDllCuaProject.iconSample.ico" )
Dim imageStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream( "TenFileDllCuaProject.imageSample.png" )
‘ Get icon/image of file resource
Dim infoIcon As System.Drawing.Image = New System.Drawing.Bitmap( iconStream )
Dim infoImage As System.Drawing.Image = New System.Drawing.Bitmap( imageStream )
[/code]
Chúc các bạn thành công!