In Microsoft Access there was an easy method to turn off screen updates by setting Echo = False. Is there an equivalent in VB.NET for WinForms? I've got a situation where I'm trying to prevent users from seeing controls flickering while they're being updated. I could probably solve the problem by coding it differently, but would rather avoid it if I can.
+1
A:
What you're looking to do is suspend and resume the redrawing of your form. There isn't a managed API for this, but it's a fairly trivial P/Invoke to do it. I don't remember the VB.NET syntax for declaring external functions right off the top of my head, but this C# example should give you the information that you need to know.
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
private const int WM_SETREDRAW = 11;
public static void SuspendDrawing(Control target)
{
SendMessage(target.Handle, WM_SETREDRAW, false, 0);
}
public static void ResumeDrawing(Control target)
{
SendMessage(target.Handle, WM_SETREDRAW, true, 0);
target.Refresh();
}
Adam Robinson
2009-08-13 05:21:02
Thanks for the help - I've found a way to declare the function in VB.NET, as follows: Public Declare Function SendMessage Lib "user32.dll" _ Alias "SendMessage" (ByVal hwnd As Integer, _ ByVal wMsg As Int32, _ ByVal wParam As Boolean, _ ByVal lParam As Int32) As IntegerHowever when I call it, it comes up with an error saying "Unable to find an entry point named 'SendMessage' in DLL 'user32.dll'.Any ideas? I'm not very experienced with API calls!
Billious
2009-08-13 06:11:19
OK, solved the problem. Found the correct declaration here: http://www.pinvoke.net/default.aspx/user32.SendMessage.Works like a charm now, thanks for pointing me in the right direction!
Billious
2009-08-13 06:26:39
A:
In C# (where this represents your form):
this.SuspendLayout();
// Make your changes
this.ResumeLayout(false);
Eric J.
2009-08-13 05:22:42
This has no effect upon redrawing, only layout operations (anchor, dock, layout controls, etc.)
Adam Robinson
2009-08-13 05:24:15