如何从中重置UserControl [英] How to Reset UserControl in From

查看:67
本文介绍了如何从中重置UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自TabControl
Tabcontrol具有tabpage1和tabpage2
将UserControl1添加到Tabpage1,将usercontrol2添加到Tabpage2

更改选择选项卡页面时出现问题,如何重置UserControl的数据

这是我的代码
http://www.mediafire.com/?6x6iiz241126dol [

My from have TabControl
Tabcontrol have tabpage1 and tabpage2
UserControl1 add to Tabpage1, usercontrol2 add to tabpage2

I have a problem when I change select tabpage, how to reset UserControl''s data

this my code
http://www.mediafire.com/?6x6iiz241126dol[^]

推荐答案

一种方法是在UserControls上建立公共功能可以为您处理其余逻辑:
One way is to make a public function on your UserControls that handles the rest logic for you:
public void Reset()
{
     /// set the default values that you want for each property here
}


然后,您可以挂接到TabControl的Deselected事件中,并调用reset函数:


Then you can hook into the TabControl''s Deselected event and call the reset function:

private void tabControl1_Deselected ( object sender, TabControlEventArgs e )
{
    switch ( e.TabPageIndex )
    {
        case 0:
            this.userControl1.Reset ();
            break;
        case 1:
            this.userControl2.Reset ();
            break;
    }
}


这篇关于如何从中重置UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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