Show a message box after usercontrol fully displayed

…衆ロ難τιáo~ 提交于 2019-12-08 12:00:47

问题


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");
    }
}

回答1:


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");
            }
        }
    }


来源:https://stackoverflow.com/questions/21303166/show-a-message-box-after-usercontrol-fully-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!