Solved

EVENT HANDLER PANEL INSIDE FLOWLAYOUT PANEL DOES NOT FIRED

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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