TableLayoutPanel中GetCellPosition和GetPositionFromControl,他们如何不同? [英] TableLayoutPanel GetCellPosition and GetPositionFromControl, how do they differ?
问题描述
这可能看起来陈腐的问题,但我觉得这些方法缺乏任何细节的微软文档。
This may seem a trite question but I find the Microsoft documentation on these methods lacking in any detail.
在<一的区别是什么href="http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.getcellposition.aspx"相对=nofollow> TablelLayoutPanel.GetCellPosition(控制控制)
和<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.getpositionfromcontrol.aspx"相对=nofollow> TableLayoutPanel.GetPositionFromControl(控制控制)
?
我使用的.NET Framework 4
I'm using .NET Framework 4
推荐答案
GetCellPosition
得到控制,所宣称的位置为 GetPositionFromControl
获得的实际位置的TableLayoutPanel
已决定了控制。这些是在大多数情况下是相同的。通过编程设置几个控件的同一个单元格(或重叠细胞 ColumnSpan
或 ROWSPAN
),看看结果如何区别
GetCellPosition
gets the declared position of the control, where as GetPositionFromControl
gets the actual position the TableLayoutPanel
has decided for the control. These are the same in most cases. Programatically set several controls to the same cell (or overlapping cells with ColumnSpan
or RowSpan
,) and see how the results differ.
添加一个TableLayoutPanel到窗体并复制以下code。运行它,并点击一个标签看看二者的区别。
Add a TableLayoutPanel to a Form and copy the following code. Run it and click on a Label to see the difference.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Index As Integer = 0 To 4
Dim Control As New Label
Control.Text = String.Format("Control {0}", Index)
AddHandler Control.Click, AddressOf Control_Click
TableLayoutPanel1.Controls.Add(Control, 0, 0)
Next
End Sub
Private Sub Control_Click(sender As Object, e As EventArgs)
Dim Pos1 As TableLayoutPanelCellPosition = TableLayoutPanel1.GetPositionFromControl(sender)
Dim Pos2 As TableLayoutPanelCellPosition = TableLayoutPanel1.GetCellPosition(sender)
Dim Text As String = String.Format("GetPositionFromControl = {0},{1}" & vbCrLf & "GetCellPosition = {2},{3}", Pos1.Column, Pos1.Row, Pos2.Column, Pos2.Row)
MessageBox.Show(Text)
End Sub
End Class
这篇关于TableLayoutPanel中GetCellPosition和GetPositionFromControl,他们如何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!