C # Making Transparent forms

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingControlexs;namespacetransform{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); ////defined on the form, the cursor is displayed as a hand shape             This. Cursor =System.Windows.Forms.Cursors.Hand; ////define the title name of the form             This. Text ="Transparent WinForm Form! "; ////define the start display position of the form is the middle of the screen             This. StartPosition =System.Windows.Forms.FormStartPosition.CenterScreen; ////The boundary of the form is FIXED3D type            //This . FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;            ////foreground color of the desktop as the foreground color of the form             This. ForeColor =System.Drawing.SystemColors.Desktop; ////define font type, size             This. Font =NewSystem.Drawing.Font ("Song Body",9); ////define the background color to be blue             This. BackColor =System.Drawing.Color.White; //set the size of a form//This .            ClientSize = new System.Drawing.Size (440, 170); //The Opacity property establishes the transparency of the form and is valid only for Windows 2000             This. Opacity =0.60; }        Private voidForm1_Load (Objectsender, EventArgs e) {             This. Setwindowtransparent ( -); }        Private voidSetwindowtransparent (byteBalpha) {            Try{Winapi.setwindowlong ( This. Handle, (int) WinAPI.WindowStyle.GWL_EXSTYLE, Winapi.getwindowlong ( This. Handle, (int) WinAPI.WindowStyle.GWL_EXSTYLE) | (UINT) WinAPI.ExWindowStyle.WS_EX_LAYERED); Winapi.setlayeredwindowattributes ( This. Handle,0, Balpha, Winapi.lwa_colorkey |Winapi.lwa_alpha); }            Catch            {            }        }        protected Overridecreateparams CreateParams {Get{createparams cp=Base.                CreateParams; Cp. Parent=Winapi.getdesktopwindow (); Cp. ExStyle=0x00000080|0x00000008;//Ws_ex_toolwindow | Ws_ex_topmost                returnCP; }        }    }}
  Public classWinAPI {[DllImport ("user32.dll")]         Public extern StaticIntPtr GetDesktopWindow (); [DllImport ("user32.dll")]         Public extern Static BOOLSetLayeredWindowAttributes (INTPTR hwnd,UINTCrkey,byteBalpha,UINTdwFlags);  Public Static UINTLwa_colorkey =0x00000001;  Public Static UINTLwa_alpha =0x00000002; [DllImport ("user32.dll")]         Public extern Static UINTSetWindowLong (INTPTR hwnd,intNIndex,UINTDwnewlong); [DllImport ("user32.dll")]         Public extern Static UINTGetWindowLong (INTPTR hwnd,intNIndex);  Public enumWindowStyle:int{Gwl_exstyle =- - }         Public enumExwindowstyle:UINT{ws_ex_layered =0x00080000 }    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.