Select Which Icon to show for form!

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
I didn't use Graphics objects before and have a problem:
I have 2 icons with .ico extension and I think I have to import them to my project resources!
Then on my forl load event I want to choose which icon will be shown as the form icon property.
I was not able to implement this simple task!
Can anyone any help?
 
Resources files

Add a resources file to your project, then import the two icons as resources. The code for a strongly-typed resource class will be automatically generated, and you can then use the class to set the Icon property of the form:

Visual Basic:
If (somecondition) Then
    Me.Icon = MyResourcesClass.Icon1
Else
    Me.Icon = MyResourcesClass.Icon2
End If

Good luck :cool:
 
The code for a strongly-typed resource class will be automatically generated

This is assuming that we are using a 2.0 version of VS. If you are using version 1.x you need to add the icon to your project, set the compile action to embedded resource, and use the Assembly.GetManifestResourceStream function to get a System.IO.Stream object that you can pass to the System.Drawing.Icon constructor. Of course, you will need more than a brief summary of the process, but I believe that there is a tutorial in the Tutor's Corner section of the forum.
 
Back
Top