winform重绘窗体成圆角(网上借鉴)

winform做圆角窗体:

 1 //重绘窗体为圆角
 2         private void frmMain_Paint(object sender, PaintEventArgs e)
 3         {
 4             #region
 5 
 6             List<Point> list = new List<Point>();
 7             int width = this.Width;
 8             int height = this.Height;
 9 
10             #region 四个圆角
11 
12             //左上  
13             list.Add(new Point(0, 5));
14             list.Add(new Point(1, 5));
15             list.Add(new Point(1, 3));
16             list.Add(new Point(2, 3));
17             list.Add(new Point(2, 2));
18             list.Add(new Point(3, 2));
19             list.Add(new Point(3, 1));
20             list.Add(new Point(5, 1));
21             list.Add(new Point(5, 0));
22 
23             //右上  
24             list.Add(new Point(width - 5, 0));
25             list.Add(new Point(width - 5, 1));
26             list.Add(new Point(width - 3, 1));
27             list.Add(new Point(width - 3, 2));
28             list.Add(new Point(width - 2, 2));
29             list.Add(new Point(width - 2, 3));
30             list.Add(new Point(width - 1, 3));
31             list.Add(new Point(width - 1, 5));
32             list.Add(new Point(width - 0, 5));
33 
34             //右下  
35             list.Add(new Point(width - 0, height - 5));
36             list.Add(new Point(width - 1, height - 5));
37             list.Add(new Point(width - 1, height - 3));
38             list.Add(new Point(width - 2, height - 3));
39             list.Add(new Point(width - 2, height - 2));
40             list.Add(new Point(width - 3, height - 2));
41             list.Add(new Point(width - 3, height - 1));
42             list.Add(new Point(width - 5, height - 1));
43             list.Add(new Point(width - 5, height - 0));
44 
45             //左下  
46             list.Add(new Point(5, height - 0));
47             list.Add(new Point(5, height - 1));
48             list.Add(new Point(3, height - 1));
49             list.Add(new Point(3, height - 2));
50             list.Add(new Point(2, height - 2));
51             list.Add(new Point(2, height - 3));
52             list.Add(new Point(1, height - 3));
53             list.Add(new Point(1, height - 5));
54             list.Add(new Point(0, height - 5));
55             #endregion
56 
57             Point[] points = list.ToArray();
58 
59             GraphicsPath shape = new GraphicsPath();
60 
61             shape.AddPolygon(points);
62 
63             this.Region = new System.Drawing.Region(shape);
64             #endregion
65         }

 

转载于:https://www.cnblogs.com/strongZZ/p/4470478.html

public void SetBits() { //绘制绘图层背景 Bitmap bitmap = new Bitmap(Main.Width + 10, Main.Height + 10); Rectangle _BacklightLTRB = new Rectangle(20, 20, 20, 20);//窗体光泽重绘边界 Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.HighQuality; //高质量 g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量 ImageDrawRect.DrawRect(g, Properties.Resources.main_light_bkg_top123, ClientRectangle, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), 1, 1); if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat)) throw new ApplicationException("图片必须是32位带Alhpa通道的图片。"); IntPtr oldBits = IntPtr.Zero; IntPtr screenDC = Win32.GetDC(IntPtr.Zero); IntPtr hBitmap = IntPtr.Zero; IntPtr memDc = Win32.CreateCompatibleDC(screenDC); try { Win32.Point topLoc = new Win32.Point(Left, Top); Win32.Size bitMapSize = new Win32.Size(Width, Height); Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION(); Win32.Point srcLoc = new Win32.Point(0, 0); hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); oldBits = Win32.SelectObject(memDc, hBitmap); blendFunc.BlendOp = Win32.AC_SRC_OVER; blendFunc.SourceConstantAlpha = Byte.Parse("255"); blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA; blendFunc.BlendFlags = 0; Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA); } finally { if (hBitmap != IntPtr.Zero) { Win32.SelectObject(memDc, oldBits); Win32.DeleteObject(hBitmap); } Win32.ReleaseDC(IntPtr.Zero, screenDC); Win32.DeleteDC(memDc); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值