如何添加表单加载事件(当前不起作用) [英] How to add a form load event (currently not working)

查看:61
本文介绍了如何添加表单加载事件(当前不起作用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Forms表单,该表单试图在加载时显示用户控件。不幸的是,它没有显示任何东西。我究竟做错了什么?请参见下面的代码:

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 code below:

AdministrationView wel = new AdministrationView();
public ProgramViwer()
{
    InitializeComponent();
}


private void ProgramViwer_Load(object sender, System.EventArgs e)
{
    formPanel.Controls.Clear();
    formPanel.Controls.Add(wel);
}

请注意,我根据本文中的内容添加了load事件:

Please note I added the load event based on what I read in this article:

http://msdn.microsoft.com/zh-cn/library/system.windows.forms.form.load.aspx

推荐答案

您可以通过三种方式执行此操作-从表单设计器中选择表单,在通常可以看到属性列表的位置,在其上方应该有一个闪电符号-这向您显示表格中的所有事件。在列表中找到表单加载事件,您应该能够从下拉列表中选择 ProgramViwer_Load

Three ways you can do this - from the form designer, select the form, and where you normally see the list of properties, just above it there should be a little lightning symbol - this shows you all the events of the form. Find the form load event in the list, and you should be able to pick ProgramViwer_Load from the dropdown.

A第二种方法是通过编程-在某个地方(可能是构造函数)将其添加,例如: ProgramViwer.Load + = new EventHandler(ProgramViwer_Load);

A second way to do it is programmatically - somewhere (constructor maybe) you'd need to add it, something like: ProgramViwer.Load += new EventHandler(ProgramViwer_Load);

使用设计器的第三种方法(可能是最快的方法)-创建新表单时,在设计模式下双击它的中间。它将为您创建一个表单加载事件,将其挂接起来,并带您到事件处理程序代码。然后,您只需添加两行就可以了!

A third way using the designer (probably the quickest) - when you create a new form, double click on the middle of it on it in design mode. It'll create a Form load event for you, hook it in, and take you to the event handler code. Then you can just add your two lines and you're good to go!

这篇关于如何添加表单加载事件(当前不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆