To cast the C # control class to a different server type

Source: Internet
Author: User
Tags foreach

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.