Creating a form and a button on the fly

  • Thread starter Thread starter Robe
  • Start date Start date
R

Robe

Hi there,

I need to create a form then add a button to it and then add the onClick
event to the button all in run time.

Can someone help me with this?

Thanks.
 
Hi there,

I need to create a form then add a button to it and then add the onClick
event to the button all in run time.

Can someone help me with this?

Thanks.

Hi,

What is what you want to do?

In any case the answer to your question.

Create the form:
Form f = new Form()
create the button
Button b = new Button()
b.onClick += myEventHander;
f.Controls.Add(b)
f.ShowDialog()
 
Hi there,

I need to create a form then add a button to it and then add the onClick
event to the button all in run time.

Can someone help me with this?

Thanks.

Hi,

What is what you want to do?

In any case the answer to your question.

Create the form:
Form f = new Form()
create the button
Button b = new Button()
b.onClick += myEventHander;
f.Controls.Add(b)
f.ShowDialog()
 
Hi,

What is what you want to do?

In any case the answer to your question.

Create the form:
Form f = new Form()
create the button
Button b = new Button()
b.onClick +=  myEventHander;
f.Controls.Add(b)
f.ShowDialog()

Sure about that:

b.onClick += myEventHandler;

statement?
 
Hi,

What is what you want to do?

In any case the answer to your question.

Create the form:
Form f = new Form()
create the button
Button b = new Button()
b.onClick +=  myEventHander;
f.Controls.Add(b)
f.ShowDialog()

Sure about that:

b.onClick += myEventHandler;

statement?
 
Sure about that:

b.onClick += myEventHandler;

statement?

I wrote the code here in google groups, so it's 100% sure it will not
compile, it will give the OP enough to find the solution to his
problem though :)

In any case, you are right it's Click onClick is a protected method
 
Sure about that:

b.onClick += myEventHandler;

statement?

I wrote the code here in google groups, so it's 100% sure it will not
compile, it will give the OP enough to find the solution to his
problem though :)

In any case, you are right it's Click onClick is a protected method
 

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