Is there a way to delay showing a form until it's fully painted? Maybe doing some kind of graphics trick.. I don't mind if it's actually not any faster, I'd just like it to seem faster :) Watching the 50 or so controls paint is a bit of an eyesore.
Thanks!
Alan C BalkanyPosted Sep 12, 2007, 1:40 PM
You can try SuspendLayout () before initializing your form and ResumeLayout () after initialization. Sometimes this doesn't work. When it doesn't, you can try using the Win32 functions:
Outside of your method:
using Microsoft.Win32;
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
private const int WM_SETREDRAW = 11;
Before drawing:
SendMessage(ObjectControlPanel.Handle, WM_SETREDRAW, false, 0);
After drawing:
SendMessage(ObjectControlPanel.Handle, WM_SETREDRAW, true, 0);
You may then need to call Refresh ().
Jud WhitePosted Aug 5, 2007, 11:32 PM
Hi Mike,
Thanks for the reply. The painting slowness happens after calling ShowDialog, after all controls have been initialized. There's no processing in the form's Load event. I think it's just the number of controls on the form (and unfortunately that can't change). I'm okay with the amount of time it takes to show the form, it's just the progressive painting that I'd like to improve.
I found a project on another site that got me half way there. A quick search for "A curtain hiding screen updates" will turn up the example. The problem this had was that the "screen freeze" was not placed in the right location, and it changed with each subsequent loading of the form, so I wasn't sure how to adjust it properly. In any case, this is the effect I'm looking for, if I could only get it to work.
Thanks again.
Mike GoldPosted Aug 5, 2007, 7:08 PM
What I've done in the past when I've had this problem is "pre-show the form and hide it with the Visible property. It's much faster to show an existing form than to load one from scratch. Also there are ways to suspend the painting of controls with BeginUpdate and EndUpdate. This method pair works with certain slow drawing controls like comboboxes and datagridviews. By calling BeginUpdate, you'll temporary freeze the painting of the control while it is being populated. Call EndUpdate after the control is populated. (perhaps in the OnLoad event).