give same property to all textbox controls

前端 未结 4 958
悲&欢浪女
悲&欢浪女 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:18

    Try:

    private void CtxMenu(Control parent)
    {
        foreach (Control child in parent.Controls)
        {
            if (child is TextBox)
            {
                (child as TextBox).ContextMenu = new ContextMenu(); 
            }
    }
    

提交回复
热议问题