本文介绍了如何将windows.form.control类型转换为特定类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在按钮单击后清除窗体上面板中所有控件的某些属性

i发送面板,其中包含一些控件作为文本框,复选框和单选按钮的功能一个类清除文本框的文本,检查复选框和单选按钮的状态但是,当我在代码中获得面板控件的类型时,我不能访问.text属性或检查状态根据控制的类型,有什么方法可以丰富它们吗?



谢谢你。





这是我的代码:





i am trying to clear some properties of all controls in a panel on a form after an button click
i send panel which contains some controls as text boxes ,check boxes and radio buttons to a function of a class to clear text of text boxes , check state of check boxes and radio buttons but ,
when i get the type of control of panel in code , i do not access to .text properties or check state according to the type of control , is any way to rich them ?

thank u .


here is my code :


public int clearControls(Control  typicalPanel)
       {

          foreach(Control ctr in typicalPanel.Controls )
          {
              System.Type InstanceType = typicalPanel.GetType();

           switch (InstanceType.Name)
           {

               case "RadioButton" :

                        // here i can not access checked property

                       ctr.Checked = false;
                  
                   break;

               case "CheckBox" :
                

                       // here i can not access checked property

                       ctr.Checked = false;
                
                   break;

               case "TextBox":

                          // here i can not access .text property

                      ctr.Text  ="";
                 
                   break;
           }

推荐答案



这篇关于如何将windows.form.control类型转换为特定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 13:31