Results 1 to 7 of 7

Thread: [RESOLVED] [2005] TableLayoutPanel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Resolved [RESOLVED] [2005] TableLayoutPanel

    I have a tablelayoutpanel set to 1 row that is loaded with a picture box in each colum. How can I tell when one of the picture boxes has been clicked on?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] TableLayoutPanel

    the pictureboxes are the same in a tablelayoutpanel as they are on a form, so you can use the picturebox_click event

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] TableLayoutPanel

    Ok that may help some but these picture boxes are created at runtime so how would I know how to build a click event then?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] TableLayoutPanel

    you need to use addhandler to specify a handler.
    try this. it adds a picturebox to your form each time you click the button.
    pictureboxes_click handles the click event of your dynamic pictureboxes.

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Static index As Integer = 0
    3.     Dim pb As New PictureBox
    4.     pb.BackColor = Color.Red
    5.     pb.Left = pb.Width * index
    6.     pb.Tag = index
    7.     index += 1
    8.  
    9.     Me.Controls.Add(pb)
    10.     AddHandler pb.Click, AddressOf pictureboxes_click
    11. End Sub
    12.  
    13. Private Sub pictureboxes_click(ByVal sender As Object, ByVal e As System.EventArgs)
    14.     MsgBox(DirectCast(sender, PictureBox).Tag)
    15. End Sub

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] TableLayoutPanel

    great example and gave me an idea. This is what i tried:

    Code:
    Private Sub pbselect()
            MsgBox("It worked George")
        End Sub
    
    
        Private Sub getpics()
            
            Debug.WriteLine(totalpic)
            For count As Integer = 0 To totalpic - 1
                pb(count) = New PictureBox
                Controls.Add(pb(count))
                With pb(count)
                    .Image = pics(count)
                    .Width = 100
                    .Height = 75
                    .Visible = True
                    .SizeMode = PictureBoxSizeMode.StretchImage
                    AddHandler .Click, AddressOf pbselect
                End With
    
            Next
    
    
    
        End Sub
    But i get an error saying:
    does not have the same signiture as deligated

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] TableLayoutPanel

    you should have a handler sub:

    vb Code:
    1. Private Sub pbselect(ByVal sender As Object, ByVal e As System.EventArgs)
    2.     'your code
    3. end sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] TableLayoutPanel

    That worked GREAT thanks a bunch

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