Raj
Raj

Reputation: 4010

Runtime control population using XML in winform application

A thought came in mind, is there any way to populate control in runtime using XML. I mean I will have one Controls.xml file and in that file I can define what control i want to add to a perticular winform and when we run that app it will show exact controls. Has anyone done this? Please guide me on this.

Upvotes: 0

Views: 518

Answers (2)

stuartd
stuartd

Reputation: 73283

Yes, you can create the controls dynamically: all you need to do is to parse the XML and then create them.

TextBox tb = new TextBox();
tb.Location = new Point(25,25);
tb.Click += textbox_Click;
this.Controls.Add (tb);

Upvotes: 1

Rosmarine Popcorn
Rosmarine Popcorn

Reputation: 10967

You can Serialize a Control (which is an Object) to XML than Deserialize se HOW TO

But the issue would be Event's ,where you should use Reflection and/or Code Injection into the Application because Event's cannot get Deserialized as an Object.

Upvotes: 0

Related Questions