Results 1 to 2 of 2

Thread: [2008] Using an ImageList load into PictureBox

  1. #1

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    [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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private imagesByButton As New Dictionary(Of Button, Image)
    2.  
    3. Private Sub Form1_Load(ByVal sender As Object, _
    4.                        ByVal e As EventArgs) Handles MyBase.Load
    5.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image1)
    6.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image2)
    7.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image3)
    8.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image4)
    9.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image5)
    10.     Me.imagesByButton.Add(Me.Button1, My.Resources.Image6)
    11. End Sub
    12.  
    13. Private Sub Buttons_Click(ByVal sender As Object, _
    14.                           ByVal e As EventArgs) Handles Button6.Click, _
    15.                                                         Button5.Click, _
    16.                                                         Button4.Click, _
    17.                                                         Button3.Click, _
    18.                                                         Button2.Click, _
    19.                                                         Button1.Click
    20.     Me.PictureBox1.Image = Me.imagesByButton(DirectCast(sender, Button))
    21. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width