modtheplanet Posted July 1, 2004 Posted July 1, 2004 I am able to create my labels with the image passed, but i want to add an event that if the user clicks on the label it displays a message box or loads another form, something like that. This is what I have, and its not even close to working. :confused: Private Sub addlabel(ByVal myImage As Bitmap) Static num As Integer Dim ctl As Control num += 1 ReDim TextBoxes(num) TextBoxes(num - 1) = New MyLabel With TextBoxes(num - 1) .Size = myImage.Size .Location = New System.Drawing.Point(10, num * (.Height + 10)) .Image = myImage AddHandler (ctl, Labels_Click) End With TabPage1.Controls.Add(TextBoxes(num - 1)) End Sub Public Sub Labels_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Labels_Click.Click MsgBox(Me.Name, "clicked") End Sub Quote
wessamzeidan Posted July 1, 2004 Posted July 1, 2004 shouldn't the addhanlder statement be something like AddHandler ctl.click, AddressOf Labels_Click Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
modtheplanet Posted July 1, 2004 Author Posted July 1, 2004 ok this will compile but will not show the label that i am creating i think that the problem lies somewhere with the: Handles MyBase.Click Private Sub addlabel(ByVal myImage As Bitmap) Static num As Integer Dim size As Integer size = myImage.Height + 25 Dim ctl As Control num += 1 ReDim TextBoxes(num) TextBoxes(num - 1) = New MyLabel With TextBoxes(num - 1) .Size = myImage.Size .Height = size .Text = "test" .Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) .TextAlign = ContentAlignment.BottomCenter .Location = New System.Drawing.Point(10, num * (.Height + 10)) .Image = myImage AddHandler ctl.Click, AddressOf Labels_Click End With TabPage1.Controls.Add(TextBoxes(num - 1)) End Sub Public Sub Labels_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click MsgBox(Me.Name, "clicked") End Sub Quote
Administrators PlausiblyDamp Posted July 1, 2004 Administrators Posted July 1, 2004 It will create it but it will be invisible, just remember to set the Visible property to true. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
modtheplanet Posted July 1, 2004 Author Posted July 1, 2004 if i comment out the addhandler line it shows the label with the image, if the addhandler line is there not commented out it doesnt, even with .visible and .enabled set to true Quote
wessamzeidan Posted July 1, 2004 Posted July 1, 2004 I don't think its the problem, but did you try to remove 'handles MyBase.Click' from the function decleration Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
wessamzeidan Posted July 1, 2004 Posted July 1, 2004 by the way, what is ctl, I think you should have AddHandler TextBoxes(num - 1).Click, AddressOf Labels_Click Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
modtheplanet Posted July 1, 2004 Author Posted July 1, 2004 thank you very much, it works now!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.