I don't know if it's called a constructor, but
How can I do it?
Thank you for your cooperation.
using System;
using System.Collections.General;
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 Form 1:Form
{
public Form 1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgse)
{
MessageBox.Show("hello world");
}
private void button1_Click(object sender, EventArgse)
{
// I want to call Form1_Load here
}
}
}
Windows 10 64-bit/Visual Studio for Desktop 2015
c#
If you want to run the Form1_Load
method or Form1.Load
Event Handler, write:
private void button1_Click (object sender, EventArgse)
{
Form 1_Load (this, EventArgs.Empty);
}
This is grammatically equivalent to MessageBox.Show("hello world")
.Although the above example specifies this
as the sender
and e
with EventArgs.Empty
and "correct as API", the actual argument value can also be null
because the Form1_Load
method does not reference the argument value.
Note that the event handler is not intended to run directly from within the code, so a more appropriate method is to define another common method and refer to Form1_Load
and button1_Click
.
private void Form1_Load (object sender, EventArgse)
{
ShowHelloWorld();
}
private void button1_Click(object sender, EventArgse)
{
ShowHelloWorld();
}
private void ShowHelloWorld()
{
MessageBox.Show("hello world");
}
© 2024 OneMinuteCode. All rights reserved.