开发者

Type of .NET control after custom based serialization?

In the process of serializing .NET control objects to custom objects (i.e. MyControlObject) to another process for some purpose, I need to re-draw these controls in a custom manner. I need to know what type it is (button, textbox, combo box, TextField, Calander, ToolStrip, TtoolstripMenu, RichTextBox, TabControl or TreeView). I might need 开发者_开发知识库a sort of typeOf(RichTextBox) == RichTextBox to check.


Yep:

if (sayMyControlObject.GetType() == typeof(TextBox))

or

if (sayMyControlObject is TextBox)

will do it, but depending on what you do with each it will probably be nicer to encapsulate that into a switch statement like so:

switch (config.GetType().Name)
{
      case "TextBox":

      break;

      case "ComboBox":

      break;

      //etc...
}


Control c = yourControl;
Type controlType = yourControl.GetType(); // will give you the type
string controlTypeName = controlType.Name; // will give you the name of the type
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜