Solved

EVENT HANDLER PANEL INSIDE FLOWLAYOUT PANEL DOES NOT FIRED

Posted on 2011-02-13
4
390 Views
Last Modified: 2012-05-11
Hi All,

Please see below code, why it does not work ?

 pnl.Controls.Add(lblType)
                pnl.Controls.Add(lblPrice)
                pnl.Controls.Add(pb)

                lblType.Dock = DockStyle.Bottom
                lblPrice.Dock = DockStyle.Bottom

                flpProfileBan.Controls.Add(pnl)

                AddHandler pnl.MouseClick, AddressOf Tyre_Profile_Click


    Private Sub Tyre_Profile_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim pnl As Panel = DirectCast(sender, Panel)

        For Each ctl As Control In pnl.Controls
            If TypeOf ctl Is Label Then
                If ctl.Name = "lblPrice" Then
                    strCurrentProfileType = ctl.Text
                End If
            End If
        Next

    End Sub

Thank you.
0
Comment
Question by:emi_sastra
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 34885486
It doesn't work because the Click NEVER reaches the Panel and therefore the event never gets fired.

Instead, you have a PictureBox and a Label that COMPLETELY cover the surface of the Panel.

If you want a "unified" click over the whole panel then wire up the Click() event for both the PictureBox and the Label instead.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34885600
Yes, it is.

AddHandler pb.MouseClick, AddressOf Tyre_Profile_Click

Now, how could I get the lbltype.text ? then sender not is picturebox.

 Private Sub Tyre_Profile_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim pnl As Panel = DirectCast(sender, Panel)

        For Each ctl As Control In pnl.Controls
            If TypeOf ctl Is Label Then
                If ctl.Name = "lblPrice" Then
                    strCurrentProfileType = ctl.Text
                End If
            End If
        Next

    End Sub

Thank you.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34885659
You could wire up both of the labels to the Tyre_Profile_Click() handlers as well:

    AddHandler pnl.MouseClick, AddressOf Tyre_Profile_Click
    AddHandler lblType.MouseClick, AddressOf Tyre_Profile_Click
    AddHandler lblPrice.MouseClick, AddressOf Tyre_Profile_Click

Now cast the sender parameter to a control, but then cast the PARENT to a Panel:

    Dim pnl As Panel = DirectCast(DirectCast(sender, Control).Parent, Panel)

So all three internal controls will fire the handler and we simply cast the Parent() control to the Panel so we can iterate and find the Label that you are looking for.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34885672
Yes, it works.

Thank you very much for your help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question