dynamic contols

  • Thread starter Thread starter MikeJ
  • Start date Start date
M

MikeJ

hi...im looking for a example of
creating controls on the fly (run time)
or a pre-created control i can copy or inherit
textbox, label, buttons

tks
MJ
 
very simple on a Form:

Button btn = new Button();
btn.Text = "Click me";
btn.Click += delegate {this.Text = "Hi";}; // or an existing
SomeMethod(object, EventArgs)
Controls.Add(btn);

Is there something more specific you want to do?

Marc
 
MikeJ,

Creating controls are like any other object, in the sense that you
create an instance, and set it's properties.

As a matter of fact, the VS.NET designer doesn't do anything special
when you set the properties of your controls, it actually emits code. It is
not declarative, like say, XAML is. You could use the designer generated
code as an example.
 
That's all I do: I create a new form, arrange the controls I want on
the screen, then look at the code that Visual Studio generated.

MikeJ,

Creating controls are like any other object, in the sense that you
create an instance, and set it's properties.

As a matter of fact, the VS.NET designer doesn't do anything special
when you set the properties of your controls, it actually emits code. It is
not declarative, like say, XAML is. You could use the designer generated
code as an example.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




hi...im looking for a example of
creating controls on the fly (run time)
or a pre-created control i can copy or inherit
textbox, label, buttons
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top