Solved

EVENT HANDLER PANEL INSIDE FLOWLAYOUT PANEL DOES NOT FIRED

Posted on 2011-02-13
4
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

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 86

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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