我想基本上根據名稱找到控制元件的位置。這是我到目前為止:
private Point FindControlLocation(string ControlName, Control ParentControl)
{
//Code...
}
謝謝你的幫助!
uj5u.com熱心網友回復:
嘗試這個:
private Point FindControlLocation(string ControlName, Control ParentControl)
{
return ParentControl.Controls[ControlName].Location;
}
這是如何使用該功能的示例:
MessageBox.Show(FindControlLocation("Button1", this).ToString());
uj5u.com熱心網友回復:
您實際上并不需要父控制元件,只需使用 Form 和以下的遞回選項Controls.Find():
private Point FindControlLocation(string ControlName)
{
Control ctl = this.Controls.Find(ControlName, true).FirstOrDefault() as Control;
return (ctl != null) ? ctl.Location : new Point();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/357985.html
