Link to home
Start Free TrialLog in
Avatar of ioustinos_sarris
ioustinos_sarrisFlag for Greece

asked on

draw an icon on the form from resources

Hi there, i am trying to retrieve an icon from my resources in order to draw it via GDI...

SO here is what i do and i keep getting null

my resource's name is tram and the icon is tram.ico


Dim list = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceNames()

Dim assembly As System.Reflection.Assembly =Me.GetType().Assembly

Me.theIcon = GetEmbeddedIcon(assembly.GetName().Name & ".tram.ico")

Form1.gMyGraphics.DrawIcon(theIcon, 20, 20)



Function GetListOfEmbeddedResources() As Array
        Return _
         System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceNames
    End Function
    Function GetEmbeddedIcon(ByVal strName As String) As Icon
        Return New Icon(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strName))
    End Function

Open in new window

Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

There is a trick actually in the constructor of the Icon class you can specify the name of the resource. See code block.
Make sure that you right clicked on the resource in the solution explorer and have set the "Build Action" property to "Embedded Resource"

Dim ico As New Icon(GetType(Form1), "blankcd.ico")
Me.Icon = ico

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of klakkas
klakkas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial