The explicit conversions of the C # control class are primarily applied to some cast types, first using foreach for type estimation, and then converting the C # control class to the corresponding type.
Questions about forcing the C # control class to be cast to another server type
All server controls within the page are type-judged by foreach, and then they are converted from the C # control class to their respective types, if the textbox and so on ...
Question added:
foreach
(Control ctl
in
this
.Controls)
{
if
(ctl的类型是Panel 而且 ID 是 PanelX)
{
将这个Panel失效,并且隐藏
}
else
(ctl的类型是Panel 而且 ID 不是 PanelX)
{
这个Panel有效,并且可见
}
}
C # control class for display conversions
foreach
(Control ctrol
in
this
.panel1.Controls )
{
if
( ctrol.GetType().ToString() == "System.Windows.Forms.TextBox" ) )
{
TextBox txt1=(TextBox)ctrol ;
}
else
if
(control
is
System.Windows.Forms.Button)
{
// control object 转成 Button object 类别
Button button = (Button)control;
// 清除 Button 上面的文字
button.Text = "";
}
}
The standard method of judgment should be:
Obj. GetType () = = typeof (System.Windows.Forms.TextBox);