Home > Article > Computer Tutorials > How to add icons in VB program
Can you elaborate on where to add the icon? I will write a program for you now. I wonder if it will be useful to this friend.
First add a new form in VB. The specific steps are: Project-Add Form-Open.
Second, add a command button on the form: name it cmddj (cmd click), and the caption attribute is "Open".
Fine-tuning content: "Third, select "Microsoft Common Dialog Control 6.0" in Project - Parts, and add the control to the newly created form in the toolbox. Note that the control is not visible at runtime and the size Not adjustable."
Fourth, draw a Picture control on the form. Moderately sized name attribute is Picture1.
Then add a click event to the cmddj control, the code is as follows
Private Sub Command1_Click()
Dim s As String
CommonDialog1.InitDir = "e:"
CommonDialog1.ShowOpen
s = CommonDialog1.FileName
Picture1.Picture = LoadPicture(s)
End Sub
When the program is running, click the "Open" button and a dialog box will appear. Then find the icon you want and click "Open" to open it.
I don’t know if what I’m talking about is what this friend wants. If it weren't for me, there would be another way.
If you want to modify the icon of the form, just modify the icon attribute of the main form. Here I recommend using VB's icon library as the icon source.
That’s it for now. If it’s not right, please contact me again.
Use IconWorkshop or other software to process icons, modify icons, add small resolution and low quality ones. If you are not sure, select them all, and then save them. You can use them in VB. In the resource manager, it is high The quality is good, but the VB form icon is of low quality. You need to use the code below to set the icon.
IconWorkshop specific steps:
Add multiple image formats after opening the icon
Just like this, if you don’t care about the file size, you can also select them all
result:
Of course vb2005 will be simpler, but the syntax of vb2005 and vb6 is very different. The original code can hardly be used
Private Const ICON_BIG = 1
Private Const ICON_SMALL = 0
Private Const WM_SETICON = &H80
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Public Sub SetWindowIcon(hWnd As Long)
Dim hIcon As Long
hIcon = ExtractIcon(App.hInstance, App.EXEName & ".exe", 0)
SendMessage hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon
SendMessage hWnd, WM_SETICON, ICON_BIG, ByVal hIcon
End Sub
The above is the detailed content of How to add icons in VB program. For more information, please follow other related articles on the PHP Chinese website!