473,503 Members | 3,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FlowLayoutPanel question

Rob
I have created a user control that has several buttons on it.....

The code below appears to add an instance of this user control to the Flow
Layout Panel just fine...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim aUnit As New MyUserControl
FlowLayoutPanel1.Controls.Add(aUnit)
End Sub

However when I run the following code... it tells me that all the user
controls have the same name in the same container (even though the location
is changing).
I know that this should not be possible. What am I doing wrong ? How can
I access a specific instance of my user control within the Flow?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ctrl As Control

For Each ctrl In FlowLayoutPanel1.Controls
MsgBox(ctrl.Name)
MsgBox(ctrl.Location.Y)
Next
End Sub
May 11 '07 #1
4 4620
On May 11, 1:32 pm, "Rob" <r...@yahoo.comwrote:
I have created a user control that has several buttons on it.....

The code below appears to add an instance of this user control to the Flow
Layout Panel just fine...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim aUnit As New MyUserControl
FlowLayoutPanel1.Controls.Add(aUnit)
End Sub

However when I run the following code... it tells me that all the user
controls have the same name in the same container (even though the location
is changing).
I know that this should not be possible. What am I doing wrong ? How can
I access a specific instance of my user control within the Flow?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ctrl As Control

For Each ctrl In FlowLayoutPanel1.Controls
MsgBox(ctrl.Name)
MsgBox(ctrl.Location.Y)
Next
End Sub
Controls don't really have names. You can use the Tag property to put
a string so you can identify a particular control. In what context do
you need to identify the control? Does your control raise events? If
so, the sender argument of the event handler will tell you which
control raised the event.

Perhaps if you provided a little information on why you need to
identify the control, a better method could be suggested.

Chris

May 11 '07 #2
Rob
Hmmm... I thought all controls had names... and no 2 controls may have the
same name within the same container or form...

When you add a Button to a form and give it a name of Button1... then add a
second Button2... try to change the Button2 name to Button1 and you get an
error.

Anyway..., basically I will be tracking time against jobs....

The user control which includes some text boxes and butttons held vs a job
gets added to the FlowLayout Panel as need by the person... then the person
fill in some data related to the job...

When the person is finished they click a button within that specific user
control and I populate a database... thus I need to know the name of the
Textbox on the specific user control "X" in order to obtain its value and
populate the db.

Hope this makes sense...

Thanks !
"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@e65g2000hsc.googlegro ups.com...
On May 11, 1:32 pm, "Rob" <r...@yahoo.comwrote:
>I have created a user control that has several buttons on it.....

The code below appears to add an instance of this user control to the
Flow
Layout Panel just fine...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim aUnit As New MyUserControl
FlowLayoutPanel1.Controls.Add(aUnit)
End Sub

However when I run the following code... it tells me that all the user
controls have the same name in the same container (even though the
location
is changing).
I know that this should not be possible. What am I doing wrong ? How
can
I access a specific instance of my user control within the Flow?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ctrl As Control

For Each ctrl In FlowLayoutPanel1.Controls
MsgBox(ctrl.Name)
MsgBox(ctrl.Location.Y)
Next
End Sub

Controls don't really have names. You can use the Tag property to put
a string so you can identify a particular control. In what context do
you need to identify the control? Does your control raise events? If
so, the sender argument of the event handler will tell you which
control raised the event.

Perhaps if you provided a little information on why you need to
identify the control, a better method could be suggested.

Chris

May 11 '07 #3
On May 11, 5:13 pm, "Rob" <r...@yahoo.comwrote:
Hmmm... I thought all controls had names... and no 2 controls may have the
same name within the same container or form...

When you add a Button to a form and give it a name of Button1... then add a
second Button2... try to change the Button2 name to Button1 and you get an
error.
Pardon my brain malfunction, you are right. I was thinking about
variable names (not properties). When you add Button1 and Button2 to
your forms, the names "Button1" and "Button2" are the names of the
Form's public fields for those buttons.
>
Anyway..., basically I will be tracking time against jobs....

The user control which includes some text boxes and butttons held vs a job
gets added to the FlowLayout Panel as need by the person... then the person
fill in some data related to the job...
So the FlowLayoutPanel is a container for one or more of these user
controls. And they get added dynamically at runtime rather than at
design time.
>
When the person is finished they click a button within that specific user
control and I populate a database... thus I need to know the name of the
Textbox on the specific user control "X" in order to obtain its value and
populate the db.
The user of the application interacts with the user controls in some
manner and then clicks a button on that control and at that point you
want to take the data in the user control and update the database.

I would suggest adding a public property to the user control which
returns the desired information (or business object). Then add an
event to the user control and raise that event when the button is
clicked. When you add the user control to the FlowLayoutPanel, wire
up this event to a common event handler. In the event handler, cast
the "sender" argument of the event to your user control class and then
access the property you added. In this way, you don't have to know
the name of the control.

'In the User Control
Public Class MyUserControl
Public Property TheInformation As String 'or whatever
End Property

Public Event SomethingHappened(ByVal sender As Object, ByVal e As
EventArgs)

Private Sub Button1_Click(...) Handles Button1.Click

RaiseEvent SomethingHappened(Me, EventArgs.Empty)
End Sub
End Class
Private Sub AddUserControl()
'Somewhere when you add an instance of the User Control to the
FlowLayoutPanel
Dim c As New MyUserControl()

'Every instance of the user control that you create, wires up the
same event handler
AddHandler c.SomethingHappened, AddressOf
HandleSomethingHappenedEvent
End Sub

Private Sub HandleSomethingHappenedEvent(ByVal sender As Object, ByVal
e As EventArgs)
'Cast the sender as your user control type
Dim mycontrol As MyUserControl = DirectCast(sender,
MyUserControl)

'Now access the string property
Dim s As String = mycontrol.TheInformation

'And if you need the Name property, you can access it
MsgBox("Control name is " & mycontrol.Name)

End Sub

Watch for typos, but I hope this gives you some ideas.

Chris

May 14 '07 #4
Rob
Thanks Chris !

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On May 11, 5:13 pm, "Rob" <r...@yahoo.comwrote:
>Hmmm... I thought all controls had names... and no 2 controls may have
the
same name within the same container or form...

When you add a Button to a form and give it a name of Button1... then
add a
second Button2... try to change the Button2 name to Button1 and you get
an
error.

Pardon my brain malfunction, you are right. I was thinking about
variable names (not properties). When you add Button1 and Button2 to
your forms, the names "Button1" and "Button2" are the names of the
Form's public fields for those buttons.
>>
Anyway..., basically I will be tracking time against jobs....

The user control which includes some text boxes and butttons held vs a
job
gets added to the FlowLayout Panel as need by the person... then the
person
fill in some data related to the job...

So the FlowLayoutPanel is a container for one or more of these user
controls. And they get added dynamically at runtime rather than at
design time.
>>
When the person is finished they click a button within that specific user
control and I populate a database... thus I need to know the name of the
Textbox on the specific user control "X" in order to obtain its value and
populate the db.

The user of the application interacts with the user controls in some
manner and then clicks a button on that control and at that point you
want to take the data in the user control and update the database.

I would suggest adding a public property to the user control which
returns the desired information (or business object). Then add an
event to the user control and raise that event when the button is
clicked. When you add the user control to the FlowLayoutPanel, wire
up this event to a common event handler. In the event handler, cast
the "sender" argument of the event to your user control class and then
access the property you added. In this way, you don't have to know
the name of the control.

'In the User Control
Public Class MyUserControl
Public Property TheInformation As String 'or whatever
End Property

Public Event SomethingHappened(ByVal sender As Object, ByVal e As
EventArgs)

Private Sub Button1_Click(...) Handles Button1.Click

RaiseEvent SomethingHappened(Me, EventArgs.Empty)
End Sub
End Class
Private Sub AddUserControl()
'Somewhere when you add an instance of the User Control to the
FlowLayoutPanel
Dim c As New MyUserControl()

'Every instance of the user control that you create, wires up the
same event handler
AddHandler c.SomethingHappened, AddressOf
HandleSomethingHappenedEvent
End Sub

Private Sub HandleSomethingHappenedEvent(ByVal sender As Object, ByVal
e As EventArgs)
'Cast the sender as your user control type
Dim mycontrol As MyUserControl = DirectCast(sender,
MyUserControl)

'Now access the string property
Dim s As String = mycontrol.TheInformation

'And if you need the Name property, you can access it
MsgBox("Control name is " & mycontrol.Name)

End Sub

Watch for typos, but I hope this gives you some ideas.

Chris

May 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3225
by: Sin Jeong-hun | last post by:
If FlowLayoutPanel's AutoScroll is set to true, there appears a scroll bar on the right. Normally, users would expect the contents is scrolled while they are dragging the scroll bar. Well, it does,...
1
8181
by: NickP | last post by:
Hi there, I am trying to implement drag and drop reordering of controls that are placed in a FlowLayoutPanel control but unfortunately as the control collection doesn't have an "insert" method I...
1
8124
by: Liam J | last post by:
Is there an upper limit on what FlowLayoutPanel will display? I wrote a test that adds 395 buttons to a flowlayoutpanel and it stopped displaying them after button 310, cutting 310 in half. It...
1
11476
by: cris.b | last post by:
There's a way to descrease the space between the controls managed in a FlowLayoutPanel? Or that space is fixed? Thank's in advice
3
12800
by: ThunderMusic | last post by:
Hi, I want to make a toolbox form (like the one in Adobe Photoshop), so I would like to put many buttons one beside the others (beside, over and under, just like the toolbox in photoshop). I...
1
7476
by: Steve Richter | last post by:
I have a form. In the Form is a MenuStrip and a FlowLayoutPanel. In the FlowLayoutPanel is a ListBox. The FlowLayoutPanel is set to DockStyle.Fill. The ListBox is set to AnchorStyles.Left |...
2
5062
by: samentu | last post by:
Hello. Is there a way to use a FlowLayoutPanel and be able to change the FlowDirection every time it goes on a new row? (I also need to have WrapContents enabled). What I want to obtain is something...
1
14534
by: sklett | last post by:
I've read several articles/blogs/threads about anchoring/docking child controls in a FlowLayoutPanel. It sounds like it *should* work, but I can't get it to work for the life of me. Jon Skeet: ...
0
3233
by: Jure Bogataj | last post by:
Hello! I have a FlowLayoutPanel placed on a form, and I'm filling it with some custom-panel controls (containing label and two checkboxes). The problem is, I want to hide horizontal scrollbar. I...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.