Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set assign an image to a control in code?

Status
Not open for further replies.

meryls

Technical User
Nov 20, 2003
62
US
I am using a version of a binding navigator that we had to modify to do some additional tasks. When the Edit button is pressed, it changes to an undo button. I would like to have the button be set to an image for Edit and for Undo in the code.

instead of
myBindingNavigator.Items(12).Text = "EDIT"

I want to set the image property to the EditTable bitmap I have imported into the resources.

Thanks for your help!
Meryl
 
You can use this method to extract the image from your embedded resources (if that is how you imported the images, I'm not sure if theres' another way).

Code:
Public Shared Function LdIcon(ByVal icn As String) As Image 
    Dim myAssembly As Assembly = Assembly.GetExecutingAssembly() 
    Dim myStream As Stream = myAssembly.GetManifestResourceStream("Namespace.Namespace2." + icn + ".bmp") 
    Dim image As Image = New Bitmap(myStream) 
    
    Return image 
End Function

You'll need to change your Namespaces leading to the .bmp files.

If you put this in a class somewhere the code becomes something like:

Code:
myBindingNavigator.Items(12).Image = MyClass.LdIcon("EditTable")

Hope this helps,

Alex

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Thanks, Alex.

How would I do this using a 'Local resource" instead of an imported one?

Thanks again!
Meryl
 
Have a look at the Image.FromFile method.

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top