give same property to all textbox controls

前端 未结 4 961
悲&欢浪女
悲&欢浪女 2021-01-24 02:02

how to give same property to all textboxes present in the same form.

      foreach (var textbox in this.Controls.OfType())
        {
            t         


        
4条回答
  •  暖寄归人
    2021-01-24 02:30

     private void SetProperty(Control ctr)
        {
            foreach(Control control in ctr.Controls)
            {
                if (control is TextBox)
                {
                    control.ContextMenu = new ContextMenu();               
                }
                else
                {
                    if (control.HasChildren)
                    {
                        SetProperty(control);
                    }                    
                }
            }
        }
    

提交回复
热议问题