recently made (mostly out of curiosity) borderless form. after making own title bar includes title, , 3 buttons(minimize, maximize , close), every normal windows program. made code these buttons (just ask if want see code).
however, i've noticed there no animations. mean that, e.g. if click minimize button, there no animation, program instantly disappears (it doesn't close, button works, without animation). happens in cases: when open program instantly appears, when close it, instantly disappears.
is there sort of way use these animations standard windows programs use?
it doesn't seem possible have animation effect on borderless form. however, there 2 possible workarounds.
set
formborderstylesizable before minimize or restore, , none aftewards.use
animatewindowfunction instead. animations tend happen window located. functions can appliedcontrol, not top level windows.
here sample code:
class forma : form { private const int wm_syscommand = 0x0112; private const int sc_minimize = 0xf020; private const int sc_restore = 0xf120; protected override void wndproc(ref message m) { switch (m.msg) { case wm_syscommand: int command = m.wparam.toint32(); if (command == sc_restore) { this.formborderstyle = formborderstyle.sizable; this.controlbox = true; } break; } base.wndproc(ref m); } } [dllimport("user32.dll")] static extern bool animatewindow(intptr hwnd, int dwtime, int dwflags); private const int aw_ver_positive = 0x00000004; private const int aw_ver_negative = 0x00000008; private const int aw_slide = 0x00040000; private const int aw_hide = 0x00010000; [stathread] static void main() { application.enablevisualstyles(); form f = new forma(); f.controlbox = false; f.formborderstyle = formborderstyle.none; bool isminimizing = false; var mb = new button { text = "min" }; mb.click += delegate { isminimizing = true; f.formborderstyle = formborderstyle.sizable; f.controlbox = true; f.windowstate = formwindowstate.minimized; f.formborderstyle = formborderstyle.none; isminimizing = false; //animatewindow(f.handle, 300, aw_slide | aw_ver_positive | aw_hide); }; f.sizechanged += delegate { if (isminimizing) return; if (f.windowstate != formwindowstate.minimized) f.formborderstyle = formborderstyle.none; }; f.controls.add(mb); application.run(f); }
Comments
Post a Comment