[.net] Problems with Hide/Show

Started by
4 comments, last by jods 18 years, 10 months ago
I am working on a program which has a main window, and then calls a new form to get user input. The problem is, when I click the "done" button, and call this.Hide(), I get a large flicker about half of the time as it appears to be redrawing the main window. This happens with both newform.Show() and newform.ShowDialog(). Also, it does not appear to occur when I use this.Close(). Any ideas? -Shane
Advertisement
Well I think it might be normal: if your input dialog is in front of your main window, when you close the dialog the main window must be repainted.

If the painting of your main window is long/complex, it may flicker a bit. If it's a problem, try to use double-buffering if you can.

Regards,
jods
Well, the main window is behind the input, but it is OpenGL, and therefore already uses double buffering.

What does flicker exactly, then ?
You may also give more details about how your application is built. Since this is .NET forum, I assume you have a WinForms application. You say your main window is OpenGL, which I understand as you use OpenGL to render the window in the Paint message.

Do you do all the painting in the WM_PAINT message ? Otherwise, the window will clear its background (OnPaintBackground) and then render itself (OnPaint) and so it could flicker, even if OpenGL rendering is double-buffered.

In .NET 1.1, you have to set the following flags:
myControl.Setstyle(Controlstyles.UserPaint | Controlstyles.AllPaintingInWmPaint, true);
Notes:
- myControl could be a form (Form inherits Control)
- the following flag may also be useful, but should not be needed since OpenGL already buffers the rendering:
myControl.Setstyle(Controlstyles.DoubleBuffer, true);

In .NET 2.0, you can set all 3 flags and enable double-buffering for a control just by setting the DoubleBuffered property to true;

It should help,
jods
Actually, the way I was doing it was just having an event handler called when the window was invalidated, and from there calling the opengl.draw function.

Is there a way to disable to background clear while still doing the rendering this way?

Or do I need to rework the way I'm rendering to the OpenGL control?

BTW, yes it is a WinForms application, and the main window has a large control into which I render with OpenGL.

[Edit]

I messed around with it a little bit, and switched from responding to invalidate to responding to paint with the same event handler.

I also removed another line that may have contributed to the problem, and it appears to work for now.
Glad that your problem was resolved.
Painting the form in response to Invalidate surely was a problem.

When you call Invalidate, you basically mark your control (or a part of it) as needing repainting. This makes windows sends a WM_PAINT message to your control, which result in OnPaint being called. So the correct way to do it is to Invalidate, and do the painting in OnPaint.

Note: if you want an immediate repainting, call Update after Invalidate. It ensures that the needed painting is done.

Regards,
jods

This topic is closed to new replies.

Advertisement