How to have program respond to code created button
-
In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?
Jordanwb wrote:
Can this be done?
Of course it can be done...just a shot in the dark here...:sigh: maybe form.close();
A craft is an enemy if not well learned.
-
Jordanwb wrote:
Can this be done?
Of course it can be done...just a shot in the dark here...:sigh: maybe form.close();
A craft is an enemy if not well learned.
-
I know how to do that, but what I want to know is how to have the program catch the button being pressed.
Place the code to close the form between the curly braces.....
private void button1_Click(object sender, EventArgs e)
{
formwhatever.close();
}This is fairly basic you know. Maybe you need a beginners book ???
A craft is an enemy if not well learned.
-
Place the code to close the form between the curly braces.....
private void button1_Click(object sender, EventArgs e)
{
formwhatever.close();
}This is fairly basic you know. Maybe you need a beginners book ???
A craft is an enemy if not well learned.
-
In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?
You also need to wire your handler to the event, as in:
button.Click+=new EventHandler(button1_Clicked);
Make sure this line executes only once (you can do it where you create the Button). In fact you can and often should program exactly the way Visual Designer does it for you when you add a Control graphically; just have a look in the code generated by Visual itself! :)Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
Actually I found what I was looking for:
this.add_button.Click += new System.EventHandler(this.save_content);
at least 3-4 articles popped up in "C# event handling" on Codeproject It is worth the time reading through. 1-2 hour & you'll be fine....
-
You also need to wire your handler to the event, as in:
button.Click+=new EventHandler(button1_Clicked);
Make sure this line executes only once (you can do it where you create the Button). In fact you can and often should program exactly the way Visual Designer does it for you when you add a Control graphically; just have a look in the code generated by Visual itself! :)Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
There are alternatives, such as - reading the documentation (MSDN, Google), - reading some articles, maybe from CodeProject - working your way through a book on either a programming language or Visual Studio. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets