How to add a form load event (currently not working)

后端 未结 2 1559
深忆病人
深忆病人 2020-12-01 23:39

I have a Windows Forms form where I am trying to show a user control when the form loads. Unfortunately, it is not showing anything. What am I doing wrong? Please see the c

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 23:58

    You got half of the answer! Now that you created the event handler, you need to hook it to the form so that it actually gets called when the form is loading. You can achieve that by doing the following:

     public class ProgramViwer : Form{
      public ProgramViwer()
      {
           InitializeComponent();
           Load += new EventHandler(ProgramViwer_Load);
      }
      private void ProgramViwer_Load(object sender, System.EventArgs e)
      {
           formPanel.Controls.Clear();
           formPanel.Controls.Add(wel);
      }
    }
    

提交回复
热议问题