조건이 TRUE 일 경우 Button_click 이벤트를 호출하려고합니다. 하지만 몇 가지 이유로 인해 작동하지 않습니다. 제발 도와 줄 수있어? 감사합니다.IF 문에 따라 BUTTON_CLICK 이벤트를 자동으로 호출합니다.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click+=button1_Click;
}
private void CheckFile()
{
FileInfo info = new FileInfo("c:\\test.txt");
if (info.Length > 0)
{
button1.PerformClick();
//this.button1.Click += new EventHandler(button1_Click);
MessageBox.Show("FILE is not empty"); //just for check
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Message POP UP");
}
public static void main(String[] args)
{
Form1 f = new Form1();
f.CheckFile();
MessageBox.Show("CheckFile called");
}
}
}