Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Panels, Labels, and Context Menu Questions 2

Status
Not open for further replies.

ulchm

Programmer
May 22, 2007
23
CA
You people were so helpful with my movable label that I decided to post regarding an old issue I had in VB.NET 1.1. Now I feel like a complete noob but here's my problems.

Panels -
Is there a way to figure out what is inside of a panel after run time? ie, which text boxes, label boxes, cbo's etc. If so, how would I go about clearing them after run time

Context Menus -
If you have contextMenu1 assigned as default when labels are created, what do you do to get the name of the label that sent the onclick event to an item in your menu. ie, label1 and label2 if I right click label2 and click a list item, I want to know that it was label2 that sent the request.

Thanks in advance for your help.
 
Controls located inside a panel are stored in the panel's Controls collection:

To iterate through them:

Code:
For each ctrl as control in YourPanel.Controls
   msgbox(ctrl.name)
End For

To clear them all:

Code:
YourPanel.Controls.Clear()


------------------------

Event handlers know who triggered the event (sender as object):

Code:
    Private Sub DraggableLabel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        'I test if the mousebutton is the right button
        'assuming you only check who is the sender
        'when there's a right click on the label
        If e.Button = MouseButtons.Right Then

            Dim lblSender As Label = DirectCast(sender, Label)

            msgbox("The name of the label who triggered the event is " & lblSender.Name)

        End If

    End Sub


Cheers!

---
[tt][COLOR=white Black]MASTA[/color][COLOR=Black lightgrey]KILLA[/color][/tt] [pipe]
 
Panels:

Panels have a Controls collection property that you can iterate through as in:

[tt]For Each ctrl As Control In Panel1.Controls
If TypeOf ctrl Is TextBox Then
With CType(ctrl, TextBox)
.Text = .....
.OtherProperty = ...
End With
ElseIf TypeOf ctrl Is CheckBox Then
With Ctype(ctrl, CheckBox)
etc.
etc.
[/tt]


ContextMenus:


You can use the sender property to determine the name and the type of control

[tt]If TypeOf Sender Is Label Then
etc.
etc.
[/tt]

or

[tt]If Sender.Name = ... Then [/tt]


Hope this helps.


[vampire][bat]
 
you guys are going to make me dependant on this website. that's NOT a good programming practice!

Thanks for the fast reply, I'll play with that a little later tonight!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top