|
-
Oct 29th, 2022, 02:32 PM
#1
Thread Starter
Hyperactive Member
Re: How to get a Control cell row and column in TableLayoutPanel?
Right. I got here so far:
Code:
Public Class Form2
Dim i As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'INCREMENT
i += 1
'MAKE GROWING ALL 50%
TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
'ADD A LABEL FOR INSTENCE
TableLayoutPanel1.Controls.Add(New Label, TableLayoutPanel1.ColumnCount - 1, 0)
'MANIPULATE ITS PROPERTIES
TableLayoutPanel1.Controls.Item(TableLayoutPanel1.ColumnCount - 1).Text = i.ToString()
TableLayoutPanel1.Controls.Item(TableLayoutPanel1.ColumnCount - 1).Dock = DockStyle.Top
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'MAKE TABLE GROW IN ROWS
TableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddColumns
End Sub
End Class
Questions:
1) Why by pressing button1 (Incrementing a column filled with a label which contains current i value) make previous text string empty?
2) Why I don't have access to other 'Label' properties? (Text orientation, Autosize, consider someone have a UserControl in it.)
I might use wrong code structure but it still runs a bit. If I did, Please tell me where's my fault.
-
Oct 29th, 2022, 08:48 PM
#2
Re: How to get a Control cell row and column in TableLayoutPanel?
 Originally Posted by pourkascheff
1) Why by pressing button1 (Incrementing a column filled with a label which contains current i value) make previous text string empty?
I'm not really sure what you mean. Can you be specific about exactly what you expect to happen and exactly what does happen.
 Originally Posted by pourkascheff
2) Why I don't have access to other 'Label' properties? (Text orientation, Autosize, consider someone have a UserControl in it.)
The Controls collection can contain any type of control, so getting an item from it will return a Control reference. That means that you can only access members of the Control class via that reference. If you want to access members of a specific control type then you have to cast as that type. Obviously the object has to be that type or the cast will fail. If you know that the control is a specific type then you can use DirectCast. If you don't know whether it's that type or not then you can use TryCast.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|