用户控件完全显示后显示一个消息框 [英] Show a message box after usercontrol fully displayed

查看:66
本文介绍了用户控件完全显示后显示一个消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个control form派生自 windows用户控件类.表单显示后,我需要根据条件显示message box.我尝试使用form paint event handler来执行此操作,但似乎触发了两次.结果,message box显示了两次.该怎么办?

I have a control form derived from a windows User Control class. I need to show a message box based on a condition once the form displayed. I tried to use the form paint event handler to do this but it seems firing twice. As a result message box displayed twice. How can this be done?

public partial class SelectAccounts : UserControl
{
    private void SelectAccounts_Paint(object sender, PaintEventArgs e)
    {
         MessageBox.Show("something");
    }
}

推荐答案

我已经删除了以前的答案,您可以尝试以下代码. 使用变量来记住是否加载了用户控件.

I've deleted my previous answer you may try the below code. Using variable to remember if the user control is loaded or not.

    public partial class SelectAccounts : UserControl
    {
        bool _Shown = false;
        private void SelectAccounts_Paint(object sender, PaintEventArgs e)
        {
            if (!this._Shown)
            {
                this._Shown = true;
                MessageBox.Show("something");
            }
        }
    }

这篇关于用户控件完全显示后显示一个消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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