110,534
社区成员
发帖
与我相关
我的任务
分享
private void ResetAllControl(Control Arge_myControl)
{
foreach (Control myControl in Arge_myControl.Controls)
{
if (!(myControl.HasChildren))
{
if (myControl.GetType().ToString() == "System.Windows.Forms.TextBox")
{
TextBox tempTexBox = myControl as TextBox;
tempTexBox.Text = "";
continue;
}
if (myControl.GetType().ToString() == "System.Windows.Forms.RadioButton")
{
RadioButton tempRadioButton = myControl as RadioButton;
tempRadioButton.Checked = false;
continue;
}
if (myControl.GetType().ToString() == "System.Windows.Forms.CheckBox")
{
CheckBox tempCheckBox = myControl as CheckBox;
tempCheckBox.Checked = false;
continue;
}
//if (myControl.GetType().ToString() == "System.Windows.Forms.NumbericUpDown")//这里是不可以执行到的,我也不知道为啥
if (myControl.GetType().ToString() == "System.Windows.Forms.UpDownBase+UpDownEdit")
{
NumericUpDown tempNumbericUpDown = myControl as NumericUpDown;//这里为null
tempNumbericUpDown.Value = 1;//所以对null对象.value是不可能的。会有异常
continue;
}
}
else
{
ResetAllControl(myControl);//递归
}
}
}
private void ResetAllControl(Control Arge_myControl)
{
foreach (Control myControl in Arge_myControl.Controls)
{
if (!(myControl.HasChildren))
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)
{
NumericUpDown tempNumberic = myControl.Parent as NumericUpDown;
tempNumberic.Value = 1;//把实际值改为1,当然这个是不会在UI上显示的
//所以接下来我们要处理显示在UI的,代码如下:
Control tempControl = tempNumberic;
#region 方法一
tempControl.Text = tempNumberic.Value.ToString();//将显示在UI上的值显示和实际的temmpNumberic.Value的值一样
#endregion
#region 方法二
//foreach (Control internalemyControl in tempNumberic.Controls)
//{
// if (internalemyControl is TextBox)
// internalemyControl.Text = tempNumberic.Value.ToString();
// continue;
//}
continue;
#endregion
}
if (myControl is System.Windows.Forms.TextBox)
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)//因为NumbericeUpDown的子控件有多么,所以在TextBox里面处理的就不处理什么了,直接跳到下一个控件
{
continue;
}
TextBox tempTexBox = myControl as TextBox;
tempTexBox.Text = "";
continue;
}
if (myControl is System.Windows.Forms.RadioButton)
{
RadioButton tempRadioButton = myControl as RadioButton;
tempRadioButton.Checked = false;
continue;
}
if (myControl is System.Windows.Forms.CheckBox)
{
CheckBox tempCheckBox = myControl as CheckBox;
tempCheckBox.Checked = false;
continue;
}
}
else
{
ResetAllControl(myControl);//递归
}
}
}
private void ResetAllControl(Control Arge_myControl)
{
foreach (Control myControl in Arge_myControl.Controls)
{
if (!(myControl.HasChildren))
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)
{
NumericUpDown tempNumberic = myControl.Parent as NumericUpDown;
tempNumberic.Value = 1;//把实际值改为1,当然这个是不会在UI上显示的
//所以接下来我们要处理显示在UI的,代码如下:
Control tempControl = tempNumberic;
#region 方法一
tempControl.Text = tempNumberic.Value.ToString();//将显示在UI上的值显示和实际的temmpNumberic.Value的值一样
#endregion
#region 方法二
//foreach (Control internalemyControl in tempNumberic.Controls)
//{
// if (internalemyControl is TextBox)
// internalemyControl.Text = tempNumberic.Value.ToString();
// continue;
//}
continue;
#endregion
}
if (myControl is System.Windows.Forms.TextBox)
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)//因为NumbericeUpDown的子控件有多么,所以在TextBox里面处理的就不处理什么了,直接跳到下一个控件
{
continue;
}
TextBox tempTexBox = myControl as TextBox;
if (tempTexBox.Text == "2" || tempTexBox.Text == "3")
{
NumericUpDown t = myControl as NumericUpDown;
if (t != null)
{
t.Value = 1;
MessageBox.Show("可转为Numberic");
continue;
}
else
{
MessageBox.Show("不可转为Numberic");
//continue;
}
}
tempTexBox.Text = "";
continue;
}
if (myControl is System.Windows.Forms.RadioButton)
{
RadioButton tempRadioButton = myControl as RadioButton;
tempRadioButton.Checked = false;
continue;
}
if (myControl is System.Windows.Forms.CheckBox)
{
CheckBox tempCheckBox = myControl as CheckBox;
tempCheckBox.Checked = false;
continue;
}
}
else
{
ResetAllControl(myControl);//递归
}
}
}
private void ResetAllControl(Control Arge_myControl)
{
foreach (Control myControl in Arge_myControl.Controls)
{
if (!(myControl.HasChildren))
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)
{
NumericUpDown tempNumberic = myControl.Parent as NumericUpDown;
tempNumberic.Value = 1;//把实际值改为1,当然这个是不会在UI上显示的
//所以接下来我们要处理显示在UI的,代码如下:
Control tempControl = tempNumberic;
#region 方法一
tempControl.Text = tempNumberic.Value.ToString();//将显示在UI上的值显示和实际的temmpNumberic.Value的值一样
#endregion
#region 方法二
//foreach (Control internalemyControl in tempNumberic.Controls)
//{
// if (internalemyControl is TextBox)
// internalemyControl.Text = tempNumberic.Value.ToString();
// continue;
//}
continue;
#endregion
}
if (myControl is System.Windows.Forms.TextBox)
{
NumericUpDown temp = myControl as NumericUpDown;
if (temp != null)
{
temp.Value = 1;
continue;
}
else
{
if (myControl.Parent is System.Windows.Forms.NumericUpDown)//因为NumbericeUpDown的子控件有多么,所以在TextBox里面处理的就不处理什么了,直接跳到下一个控件
{
continue;
}
TextBox tempTexBox = myControl as TextBox;
if (tempTexBox.Text == "2" || tempTexBox.Text == "3")
{
NumericUpDown t = myControl as NumericUpDown;
if (t != null)
{
t.Value = 1;
MessageBox.Show("可转为Numberic");
continue;
}
else
{
MessageBox.Show("不可转为Numberic");
//continue;
}
}
tempTexBox.Text = "";
continue;
}
}
if (myControl is System.Windows.Forms.RadioButton)
{
RadioButton tempRadioButton = myControl as RadioButton;
tempRadioButton.Checked = false;
continue;
}
if (myControl is System.Windows.Forms.CheckBox)
{
CheckBox tempCheckBox = myControl as CheckBox;
tempCheckBox.Checked = false;
continue;
}
}
else
{
ResetAllControl(myControl);//递归
//Thread myThread = new Thread(delegate() { ResetAllControl(myControl); });
//myThread.Start();
//myControl.Invoke(mydelegate(),myControl);
}
}
}
private void ResetAllControl(Control Arge_myControl)
{
foreach (Control myControl in Arge_myControl.Controls)
{
if (!(myControl.HasChildren))
{
//if (myControl.GetType().ToString() == "System.Windows.Forms.TextBox")
//这里倒奇怪了,也把我的NumbericUpDown都空为空了,但他的NumbericUpDown.Value还是有的。
//这也说明了,原来NumbericUpDown就是一个合成的控件。因为我处理TextBox,也对他有影响。
//看来楼上朋友所说的myControl is NumbericUpDown还是解决不了我的问题。
if (myControl is System.Windows.Forms.TextBox)
{
TextBox tempTexBox = myControl as TextBox;
tempTexBox.Text = "";
continue;
}
if (myControl.GetType().ToString() == "System.Windows.Forms.RadioButton")
{
RadioButton tempRadioButton = myControl as RadioButton;
tempRadioButton.Checked = false;
continue;
}
if (myControl.GetType().ToString() == "System.Windows.Forms.CheckBox")
{
CheckBox tempCheckBox = myControl as CheckBox;
tempCheckBox.Checked = false;
continue;
}
//if (myControl.GetType().ToString() == "System.Windows.Forms.NumbericUpDown")
//if (myControl.GetType().ToString() == "System.Windows.Forms.UpDownBase+UpDownEdit")
if(myControl is NumericUpDown)//这里没有这个可以成功执行
{
NumericUpDown tempNumbericUpDown = myControl as NumericUpDown;//这里为null
tempNumbericUpDown.Value = 1;//所以对null对象.value是不可能的。会有异常
continue;
}
}
else
{
ResetAllControl(myControl);//递归
//Thread myThread = new Thread(delegate() { ResetAllControl(myControl); });
//myThread.Start();
//myControl.Invoke(mydelegate(),myControl);
}
}
}