Frage

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");
    }
}
War es hilfreich?

Lösung

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");
            }
        }
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top