用户控件Load事件不解雇 [英] UserControl Load event not fired

查看:171
本文介绍了用户控件Load事件不解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WinForms应用程序。我的形式派生类用户控件派生类。
我只是把几个控件为一个用户控件,以简化重用。 用户控件加载事件不被解雇。我一定要设置一些财产?


解决方案

尝试重写的的OnLoad()方法。从MSDN:


  

在onload方法还允许派生
  类来处理事件,而不
  附加委托。这是在
  preferred技术用于处理
  事件在派生类中。


 保护覆盖无效的OnLoad(EventArgs的发送)
{
    //你的code到负载运行到这里    //调用基类的OnLoad,以确保任何委托事件处理仍在callled
   base.OnLoad(E);
}

I have WinForms application. My Form derived class has UserControl derived class. I simply put several controls into one UserControl to simplify reuse. The Load event of UserControl is not fired. Do I have to set some property?

解决方案

Try overriding the OnLoad() method in your UserControl. From MSDN:

The OnLoad method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

protected override void OnLoad(EventArgs e)
{
    //Your code to run on load goes here 

    // Call the base class OnLoad to ensure any delegate event handlers are still callled
   base.OnLoad(e);
}

这篇关于用户控件Load事件不解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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