Home>
Nice to meet you. I am learning C# from today.
I've heard about the Close method.
If i write this.Close();in button1, the form will close properly,
Even if you write this.Close();of button2, the form does not close.
I'd like the form to close on button2, but I'm having trouble understanding why it doesn't.
We apologize for such questions, but we would appreciate your answer.
Applicable source code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
What I tried
I looked up the Close method on the net to find out what was wrong, but I'm not sure.
Supplementary information (FW/tool version, etc.)I am using Visual Studio 2015.
-
Answer # 1
-
Answer # 2
Let's set a breakpoint at this.Close();(click the line there to mark it) and see if execution stops there.
If you don't go there when you click the button, it won't close.
Related articles
- go - for c: = range ch {} about the method of close (ch) when sending a value to ch in the clause
- java - this is a question about an application problem using a simple for statement
- i have a question about queryselectorall in javascript
- this is a question about changing the table format of standard sql
- [javascript] question about a little special graph drawing
- vuejs - question about how to arrange side by side using v-for in vue
- javascript - i have a question about how to specify variables in mainjs
- java - about method overloading
- postgresql - about cross-join in the question about the percentile of 100 data scientist knocks
- java - about the get method
- java - i have a question about new
- about the output result of iloc method of python
- python 3x - [python] about the method of totaling for each data frame and element
- java print method? about
- ruby - i have a question about rails routing errors
- i have a question about a problem with python i tried many times
- programming language - about method argument types
- python - about image processing of hog method
- [java] about equals method (reason why nullpointerexception does not occur even if null is passed/override)
- please tell me about the extraction method when the parentheses of the json part are nested in python3 scraping
Trends
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
When espering, button2_Click just copy and copy button1_Click and rewrite 1 into 2, and button 2 (name is automatically created) is added regardless of that, so no event handler is registered.
In that case, after adding button 2, the event handler is automatically generated by the same procedure as button 1, and then the processing inside (
this.Close();
) Let's copy and pasteWhat if we made button2_Click first? In that case, let's examine the procedure for adding an existing method to the event handler of the button.