Solved

EVENT HANDLER PANEL INSIDE FLOWLAYOUT PANEL DOES NOT FIRED

Posted on 2011-02-13
4
363 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now