Friday, March 6, 2009

Get and Compare the Control

Some of the time we need to know what kind ok control are we dealing with. This simple example mimics how to know what is our control.

As an example say we want to go through the form’s controls and show a message if there were a text box.


foreach (Control n in this.Controls) {

String tp = "System.Windows.Forms.TextBox";

   if (n.GetType().ToString() ==tp){

         // Do something

    }

}

  

 

Post a Comment