|
|
Title | Change a form's icon at run time in VB .NET |
Description | This example shows how to change a form's icon at run time in VB .NET. It sets the form's Icon property to a new Icon object taken from an embedded resource. |
Keywords | icon, VB .NET |
Categories | VB.NET, Graphics, Controls |
|
|
To make an embedded icon resource, make the icon file. You can use an external tool or the IDE's icon editor. Personally, I like to draw the icon in MSPaint or some other program and then copy and paste it into the integrated icon editor.
After you add the icon file to the project, select it in Project Explorer. Then in the Properties window, set its Build Action property to Embedded Resource.
At run time, create a new Icon object passing the constructor the type of an object in the assembly containing the resource and the name of the resource. Set the form's Icon property to the new Icon.
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
radHappy.Checked = True
End Sub
Private Sub radHappy_Click(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles radHappy.Click
Me.Icon = New Icon(Me.GetType(), "Happy.ico")
End Sub
Private Sub radSad_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles radSad.Click
Me.Icon = New Icon(Me.GetType(), "Sad.ico")
End Sub
|
|
|
|
|
|