如何添加一个窗体加载事件(当前不工作) [英] How to add a form load event (current not working)

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

问题描述

我在哪里,我想表明,当窗体加载用户控件的Windows窗体。 Unforunately,它没有显示任何东西。我究竟做错了什么?请参考下面code:

I have a windows form where I am trying to show a user control when the form loads. Unforunately, it is not showing anything. What am I doing wrong? Please see 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:

<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.form.load.aspx\">http://msdn.microsoft.com/en-us/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.

做的第二种方法是通过编程 - 地方(也许构造函数),你需要添加它,是这样的: ProgramViwer.Load + =新的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);

使用设计器(可能是最快的)第三种方式 - 当你创建一个新的形式,双上它是在设计模式中,中间点击。它会为你创建一个Form Load事件,把它挂在,并带您到事件处理程序code。然后,你可以添加两行,你是好去!

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天全站免登陆