【问题标题】:how to find a control's location based on the control's name如何根据控件的名称查找控件的位置
【发布时间】:2021-12-25 05:38:23
【问题描述】:

我想基本上根据名称找到控件的位置。这是我目前所拥有的:

private Point FindControlLocation(string ControlName, Control ParentControl)
{
    //Code...
}

感谢您的帮助!

【问题讨论】:

    标签: c# winforms controls


    【解决方案1】:

    您实际上并不需要父控件,只需使用 Controls.Find() 中的 Form 和递归选项:

    private Point FindControlLocation(string ControlName)
    {
        Control ctl = this.Controls.Find(ControlName, true).FirstOrDefault() as Control;
        return (ctl != null) ? ctl.Location : new Point();
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-23
      • 2014-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      相关资源
      最近更新 更多