The MDI form does not blink method test pass:
//. NET 4.0 with Optimizeddoublebuffer
This. SetStyle (Controlstyles.optimizeddoublebuffer | Controlstyles.userpaint | Controlstyles.allpaintinginwmpaint, True);
This. UpdateStyles ();
A really effective method: Add the top-level form
protected override CreateParams CreateParams {
get {
CreateParams CP = base. CreateParams;
Cp. ExStyle |= 0x02000000; Turn on ws_ex_composited
return CP;
}
}
On the lower-level forms and custom controls plus
protected override CreateParams CreateParams
{
Get
{
CreateParams CP = base. CreateParams;
Cp. Style &= ~0x02000000; Turn off Ws_clipchildren
return CP;
}
}
Note: If you add the wrong place or the character is not good, some times may cause the control to draw slightly not normal.
If the character burst, it seems that the lower form directly add CP. Style &= ~0x02000000 on the line, do not need to add CP in the upper form. ExStyle |= 0x02000000;
Note that the downlevel form code in the ListBox or the anchor of the ListView has right, and the form BackColor differs from the background of the control, you may find that the control initialization is not displayed properly. Need to do a Mdiparent.refresh or cancel right
Refer to the description of CreateParams in MSDN:
Do not override this property in the overloaded control you are developing, and control some of the style of the control with this property. Use this property only if you are encapsulating Windows controls or want to implement some style (such as layered Window) control that some WinForm do not provide. For more information, refer to the documentation comments on MSDN for the CreateWindow method and the parameters of the CreateWindowEx method createstruct structure.
Briefly explain why CreateParams can achieve such advanced style control, since the names of CreateWindow and CreateWindowEx show that Createparam is a parameter passed to both methods, These two methods are also called when the form is created. So, Createparam can achieve such a powerful style control.
node update to use BeginUpdate and endupdate
This pair of actions has a good effect on scenarios that require bulk manipulation of the update control, such as a large number of nodes being added in bulk during initialization. The downside is that you can't update it instantly. Therefore, for frequent update nodes and want to immediately reflect the situation to the interface is not applicable. If you use and do not disable the clear interface message, the control will appear to flicker, and the white background is dominated, the content is almost invisible (this depends on the degree of frequency). Because the interface updates are done at endupdate, too many operations cause the endupdate to block for too long, and are emptied before the update, causing the interface to appear to be in a blank state for a long time.
In some cases, you can use the Suppress background update
protected override void WndProc (ref Message m)
{
if (m.msg = = 0x0014) return;//Erase background message
Base. WndProc (ref m);
}
Public LISTVIEWNF ()
{
Turn on double buffering
This. SetStyle (Controlstyles.optimizeddoublebuffer | Controlstyles.allpaintinginwmpaint, True);
Enable The Onnotifymessage event so we get a chance to filter out
Windows messages before they get to the form ' s WndProc
This. SetStyle (Controlstyles.enablenotifymessage, true);
}
protected override void Onnotifymessage (Message m)
{
Filter out the WM_ERASEBKGND message
if (m.msg! = 0x14)
{
Base. Onnotifymessage (m);
}
}
******************************************
Using the LockWindowUpdate API
[DllImport ("User32.dll")]
static extern bool LockWindowUpdate (IntPtr hwndlock);
LockWindowUpdate (Panelcontainer.handle);
Clear Panel
PanelContainer.Controls.Clear ();
My temporary TextBox
TextBox MyT;
for (int lauf=0; Lauf <; lauf++)
{
Create New TextBox
MyT = new TextBox ();
Add TextBox to the Panel
PANELCONTAINER.CONTROLS.ADD (MyT);
}
Redraw the window
LockWindowUpdate (IntPtr.Zero);
Frmchild1.hide (); Hides the currently displayed subform 2 3 lockwindowupdate (this. Handle); Lock parent Form 4 frmchild2.show (); Show forms and other things you need to show before you do 5 lockwindowupdate (IntPtr.Zero); Unlocks the parent Form 6 RedrawWindow (this. Handle, IntPtr.Zero, IntPtr.Zero,
Rdw_erase | Rdw_invalidate | Rdw_allchildren); (0x04 | 0x01 | 0x80) immediately forces the redraw of the parent form and all its child forms
The effect is improved, but the human eye can still see some flower screen phenomenon, still can not fully display at once.
3. Use the SendMessage function in the Windows API:
Intercept control Redraw
class
DrawingControl
{
[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 parent )
{
SendMessage(parent.Handle, WM_SETREDRAW,
false
, 0);
}
public
static
void
ResumeDrawing( Control parent )
{
SendMessage(parent.Handle, WM_SETREDRAW,
true
, 0);
parent.Refresh();
}
}
1 Frmchild1.hide (); 2 3 SendMessage (this. Handle, Wm_setdraw, false, NULL); Prohibit drawing operations in a form-----
14 Frmchild2.show (); Show the form and other things that need to be displayed before you do 5 SendMessage (this. Handle, Wm_setdraw, true, null); Suppresses the draw operation-----
26 RedrawWindow (this. Handle, IntPtr.Zero, IntPtr.Zero,
Rdw_erase | Rdw_invalidate | Rdw_allchildren); (0x04 | 0x01 | 0x80) forces the parent form and all its child windows to be redrawn immediately
In the SendMessage function, send the message wm_setredraw, set SetRedraw to False, causing the window not to be drawn.
At this point, the form you see is false, the phenomenon:
The mouse shape is the shape of the back application;
The mouse is over, and the application behind it is displayed.
The human eye sees is "the flower screen".
Winform MDI form switching does not blink solution (test pass)