C# THIS.INVALIDATE() IS BLOCKING PARENT FORM TO ACCESS

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
C#
 1502  View(s)
Ratings:
Rate this:

I have a button on MainForm whose button click event creates a ChildForm and shows. While ChildForm is shown, i can invoke any menu commands (each menu command is implemented to show a message box) which are defined on MainForm without any issues.

BUT, on other hand, I kept all the code as is and override OnPaint method of ChildForm with this.Invalidate() as shown below

protected override void OnPaint(PaintEventArgs e)

    {

        this.Invalidate();

        base.OnPaint(e);

    }

Can anyone put some light on what went wrong with overriding OnPaint method which executes this.Invalidate() line everytime and suggest how can I resolve this issue.

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: C# this.Invalidate() is blocking parent form to access

    Hi Tanuj,

    You called Invalidate() which will fire OnPaint, OnPaint calls Invalidate() and again ... that's a loop of calling Invalidate() and OnPaint -> Your UI is frozen.

    The solution is you have to make it more clear on what you want and your purpose of overriding OnPaint here.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!