event

Page update date :
Page creation date :

Events are meant to be commensurate with the user's interaction when they do so. The programmer can skip processing to a specified method when the event occurs. It is almost always used in tools etc.

As an exercise, let's create a program that displays a message box when the form is clicked with the mouse.

The first thing to do is display the designer of the form. Click "MainForm.cs [Design]" from the tab above. If it is closed, double-click "MainForm .cs" from the solution explorer. Right-click "Show Designer" is also good.

デザイン

デザイナの表示

When the designer appears, open "Properties" (before that, click on the form to focus on it. Otherwise, you may not see it as shown below), press the "Event (lightning bolt button)" above the property window.

イベントボタン

Since the items like the following are displayed, please double-click the part of the character of "MouseDown".

MouseDown

Then you go to the code editor and see that a new method has been added.

新しいメソッド

This "MainForm_MouseDown" method is called when you click the mouse. Now, try putting the following code inside this method:

コード追加

MessageBox.Show("マウスクリック!");

Try running it. I think clicking on the form will bring up the dialog below.

マウスクリック!

The event looks like this. For the time being, I'll remove this event for testing purposes. To delete, open the event from the previous properties, right-click on "MouseDown" and select "Reset". This prevents this event from being executed. The code remains in the code file, so delete it as is.

イベントリセット