Pregunta

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");
    }
}
¿Fue útil?

Solución

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");
            }
        }
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top