#regionUpdatelayeredwindow#regionOverriding the CreateParams property of a formprotected Overridecreateparams CreateParams {Get{createparams cp=Base. CreateParams; Cp. ExStyle|=0x00080000;//ws_ex_layered Extended Styles//No Border taskbar window minimized Const intWs_minimizebox =0x00020000;//defined in Winuser.h//createparams CP = base. CreateParams;Cp. Style = CP. Style | Ws_minimizebox;//allow minimization of operations returnCP; } } #endregion #regionAPI calls Public voidSetbits (Bitmap Bitmap)//Call the Updatelayeredwindow () method. This. BackgroundImage is a transparent picture that you prepared beforehand. { //if (!havehandle) return; if(! Bitmap.iscanonicalpixelformat (Bitmap. PixelFormat) | | !Bitmap.isalphapixelformat (Bitmap. PixelFormat))Throw NewApplicationException ("the picture must be a 32-bit picture with ALHPA channels. "); INTPTR oldbits=IntPtr.Zero; INTPTR SCREENDC=Win32.getdc (IntPtr.Zero); INTPTR Hbitmap=IntPtr.Zero; INTPTR MEMDC=Win32.createcompatibledc (SCREENDC); Try{win32.point Toploc=NewWin32.point (left, Top); Win32.size bitmapsize=Newwin32.size (bitmap. Width, Bitmap. Height); Win32.blendfunction Blendfunc=Newwin32.blendfunction (); Win32.point Srcloc=NewWin32.point (0,0); Hbitmap= Bitmap. Gethbitmap (Color.FromArgb (0)); Oldbits=Win32.selectobject (MEMDC, HBITMAP); Blendfunc.blendop=Win32.ac_src_over; Blendfunc.sourceconstantalpha=255; Blendfunc.alphaformat=Win32.ac_src_alpha; Blendfunc.blendflags=0; Win32.updatelayeredwindow (Handle, SCREENDC,refToploc,refBitmapsize, MEMDC,refSrcloc,0,refBlendfunc, Win32.ulw_alpha); } finally { if(Hbitmap! =IntPtr.Zero) {win32.selectobject (MEMDC, oldbits); Win32.deleteobject (HBITMAP); } win32.releasedc (IntPtr.Zero, SCREENDC); Win32.deletedc (MEMDC); } } #endregion #endregion
Public mainform () { InitializeComponent (); New Bitmap (this. Height); = graphics.fromimage (BG); G.drawimage (IMG, x, Y, img). Width, IMG. Height); G.dispose (); Setbits (BG); }
C # Updatelayeredwindow Profiled window