|
-
Jan 26th, 2009, 10:50 PM
#1
Thread Starter
Addicted Member
[2008] Using an ImageList load into PictureBox
I want to make an image display when mouse enter in my following buttons...
I have a 6 buttons....button1, button2, button3 ,button4, button 5 and button 6....
And i have also a pictureBox1
Now if the mouse is enter for each buttons my pictureBox1 will display a different image for each button in one control called "PictureBox1"
Do i Need to use ImageList?
-
Jan 26th, 2009, 11:04 PM
#2
Re: [2008] Using an ImageList load into PictureBox
While you can use an ImageList, I wouldn't use one. There are certain controls that require you to use an ImageList, like ListView and TreeView, and I'd only use an ImageList in those cases.
In your case, I'd add my images to the Resources tab of the project properties. You can then create a Dictionary containing Buttons and Images like this:
vb.net Code:
Private imagesByButton As New Dictionary(Of Button, Image) Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load Me.imagesByButton.Add(Me.Button1, My.Resources.Image1) Me.imagesByButton.Add(Me.Button1, My.Resources.Image2) Me.imagesByButton.Add(Me.Button1, My.Resources.Image3) Me.imagesByButton.Add(Me.Button1, My.Resources.Image4) Me.imagesByButton.Add(Me.Button1, My.Resources.Image5) Me.imagesByButton.Add(Me.Button1, My.Resources.Image6) End Sub Private Sub Buttons_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles Button6.Click, _ Button5.Click, _ Button4.Click, _ Button3.Click, _ Button2.Click, _ Button1.Click Me.PictureBox1.Image = Me.imagesByButton(DirectCast(sender, Button)) End Sub
That is by no means the only way to do what you want but it's the way I'd probably do it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|