Reputation: 141
I have a VS2010 solution (tried mimicking my main issue) which has 2 project and each project has one windows form each. Mainform is in project_1 which has reference to project 2 where ChildForm is defined.
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);
}
I ran executable and it opened up my MainForm and clicked on button to open up my ChildForm, then clicked on one of the Menu command to raise a message box, then I found that both MainForm and ChildForms are frozen and are hanged without any response.
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.
Regards, Kumar
Upvotes: 0
Views: 417
Reputation: 63327
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.
Upvotes: 1