winforms - Turn off 'Show window contents while dragging' setting while displaying my C# windows forms -


there window display setting called 'show window contents while dragging'.

http://www.thewindowsclub.com/disable-show-windows-contents-while-dragging

when setting turned on, if drag window window repaint @ new position. if resize window, repaint window each new window size immediately, if still holding down mouse button.

when setting turned off, dragging or resizing window shows outline of new window position or size until release mouse button , paint window @ new position or size.

i display forms in c# winforms application 'show window contents while dragging' setting turned off. operating setting, effective when forms displayed regardless of setting set in os.

is there way achieve using winapi calls change behavior winforms?

if not, there way can change setting programatically before form displayed , reset after form has closed? performing change require admin rights (because don't want that)?

the following code below use system setting of 'show window content while dragging' window re-positioning, while temporarily set off, while resizing window , set system setting.

this gives flicker free form resizing in windows forms.

since property user setting modifies hkey_current_user\control panel\desktop\dragfullwindows registry key, should not require admin rights.

    [dllimport("user32.dll", entrypoint = "systemparametersinfo", charset = charset.auto)]     public static extern int getsystemparametersinfo(int uaction, int uparam, out int lpvparam, int fuwinini);      [dllimport("user32.dll", entrypoint = "systemparametersinfo", charset = charset.auto)]     public static extern int setsystemparametersinfo(int uaction, int uparam, int lpvparam, int fuwinini);      private const int spi_getdragfullwindows = 38;     private const int spi_setdragfullwindows = 37;      private const int wm_syscommand = 0x0112;     private const int sc_size = 0xf000;       //change 'show window content while dragging' false while resizing     protected override void wndproc(ref message m)     {         if (m.msg == wm_syscommand && (m.wparam.toint32() & 0xfff0) == sc_size)         {             int isdragfullwindow;             getsystemparametersinfo(spi_getdragfullwindows, 0, out isdragfullwindow, 0);              if (isdragfullwindow != 0)                 setsystemparametersinfo(spi_setdragfullwindows, 0, 0, 0);              base.wndproc(ref m);              if (isdragfullwindow != 0)                 setsystemparametersinfo(spi_setdragfullwindows, 1, 0, 0);         }         else         {             base.wndproc(ref m);         }     }       //reduce control flickering , black stripes when window resized     protected override createparams createparams     {                 {             createparams cp = base.createparams;             cp.exstyle |= 0x02000000;  // turn on ws_ex_composited             return cp;         }     } 

Popular posts from this blog