获取控件的位置 [英] Get location of a control
本文介绍了获取控件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用C#/.NET获取Windows窗体应用程序中特定控件的位置.
请帮助我.
[edit] OP已添加为评论:
我想在一个面板内生成多个动态标签,并且我有1种以上的表单,所以如何动态地处理所有标签-amitthakkar1987
OriginalGriff [/edit]
I want to get the location of a particular control using C#/.NET for a Windows Forms application.
Please help me with this.
[edit]OP added as a comment:
i want to generate a dynamic label multiple inside a panel and i have more than 1 forms so how to handle it all dynamically - amitthakkar1987
OriginalGriff[/edit]
推荐答案
Control.Location属性对我有用...
The Control.Location property does it for me...
如果面板是面板的一部分形式,然后使用面板名称(将其命名为MyPanel)
然后,将标签控件添加到面板中-我们将假定标签字符串位于名为myLabelStrings的数组或列表中:
If the panel is part of the form, then use the panel name (lets call it MyPanel)
Then, add your label controls to the panel - we will assume the label strings are in an array or list called myLabelStrings:
int x = 10;
int y = 10;
foreach (string s in myLabelStrings)
{
Label l = new Label();
l.Text = s;
l.Location.X = x;
l.Location.Y = y;
l.Visible = true;
y += 50;
MyPanel.Controls.Add(l);
}
这篇关于获取控件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文