1. Gradient form
Set a timer interval to 100 and add it to the response function.
private void Form1_Load(object sender, System.EventArgs e) { this.timer1.Enabled=true; this.Opacity=0; } private void timer1_Tick(object sender, System.EventArgs e) { if(this.Opacity<1) { this.Opacity=this.Opacity+0.05; } else { this.timer1.Enabled=false; } }
2. Set the top-level window
Set topmost and toplevel to true!
3. Set a Polygon Window.
Introduce the function to be used
[DllImport("gdi32")]private static extern IntPtr CreatePolygonRgn(Point[] lpPoint,int nCount,int nPolyFillMode);[DllImport("user32")]private static extern IntPtr SetWindowRgn(IntPtr hWnd,IntPtr hRgn,bool bRedraw);
Set the shape when loading the window!
Point[] pt={ new Point(this.Width /2,0), new Point(0,this.Height/2), new Point(this.Width/2,this.Height), new Point(this.Width,this.Height/2), new Point(this.Width,0) }; IntPtr m_rgn; m_rgn=CreatePolygonRgn(pt,5,WINDING); SetWindowRgn(this.Handle,m_rgn,true);
4. Set a circular window
[System. runtime. interopservices. dllimport ("GDI32")] Private Static extern intptr beginpath (intptr HDC); [system. runtime. interopservices. dllimport ("GDI32")] Private Static extern int setbkmode (intptr HDC, int nbkmode); const int transparent = 1; [system. runtime. interopservices. dllimport ("GDI32")] Private Static extern intptr endpath (intptr HDC); [system. runtime. interopservices. dllimport ("GDI32")] Private Static extern intptr pathtoregion (intptr HDC); [system. runtime. interopservices. dllimport ("GDI32")] Private Static extern int ellipse (intptr HDC, int X1, int Y1, int X2, int Y2); [system. runtime. interopservices. dllimport ("USER32")] Private Static extern intptr set1_wrgn (intptr hwnd, intptr hrgn, bool bredraw); [system. runtime. interopservices. dllimport ("USER32")] Private Static extern intptr getdc (intptr hwnd); Private void form1_load (Object sender, system. eventargs e) {intptr DC; intptr region; DC = getdc (this. handle); beginpath (DC); // create an irregular form setbkmode (DC, transparent) based on the path; // set it to transparent mode ellipse (DC, 20, 20, 220,220 ); endpath (DC); region = pathtoregion (DC); set1_wrgn (this. handle, region, true);} const int wm_nchittest = 0x0084; const int htclient = 0x0001; const int htcaption = 0x0002; protected override void wndproc (Ref system. windows. forms. message m) {Switch (M. MSG) {Case wm_nchittest: base. wndproc (ref m); If (M. result = (intptr) htclient) M. result = (intptr) htcaption; break; default: base. wndproc (ref m); break ;}}}
5. Gradient window background
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g=e.Graphics; Color FColor=Color.Blue; Color TColor=Color.Yellow; Brush b =new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.ForwardDiagonal); g.FillRectangle(b,this.ClientRectangle); } private void Form1_Resize(object sender, System.EventArgs e) { this.Invalidate(); }
6. Drag the Untitled window
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd,int wMsg,int wParam,int lParam); public const int WM_SYSCOMMAND=0x0112; public const int SC_MOVE=0xF010; public const int HTCAPTION=0x0002; private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0); }
This series of articles is the author's learning about Visual C #. NET application programming 150 cases (source code) experience notes, welcome to reprint, please indicate the original address, if you have any questions, you can contact the author through the 278250658@qq.com.
Author: ryanding