什么是表单“On_Load"?相当于控件? [英] What is the Form "On_Load" equivalent for Controls?

查看:35
本文介绍了什么是表单“On_Load"?相当于控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 listBox,我想在它加载时执行一个方法,尽管我不能使用 FormOn_Load"触发器,因为 ListBox 在 TabControl 内.

I have a listBox that I would like to carry out a method when its loaded up, although I can't use the Form "On_Load" trigger, since the ListBox is within a TabControl.

有没有办法在对象初始化时得到一个方法来执行?

Is there a way of getting a method to execute when the object initializes?

推荐答案

正如@SLaks 所说,您可以放入类的构造函数.但是,如果您要准备的内容依赖于表单中的其他元素,您可以在表单加载结束时添加到事件处理程序队列,但在其实际呈现给用户之前.

As @SLaks stated, you could put in your class's constructor. However, if what you want to prepare relies on other elements in the form, you can add to the event handler queue at the end of a form loading, but before its actually presented to the user.

在你的表单的构造函数代码(不是设计器代码)中,添加到加载事件中,然后添加你自己的自定义函数

In the constructor code of your form (not the designer code), add to the load event, then add your own custom function

public partial class frmYourForm : Form
{
    public frmYourForm()
    {
       Load += YourPreparationHandler;
    }

    private void YourPreparationHandler(object sender, EventArgs e)
    {
        // Do you code to prepare list, combos, query, bind, whatever
    }
}

这篇关于什么是表单“On_Load"?相当于控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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