winform创建不规则窗体的方法

2019-12-26 13:15:10刘景俊

易采站长站为您分析winform创建不规则窗体的方法,涉及C#窗体创建的相关参数设置技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了winform创建不规则窗体的方法。。具体如下:

 

 
  1. using System;  using System.Collections.Generic; 
  2. using System.ComponentModel;  using System.Data; 
  3. using System.Drawing;  using System.Text; 
  4. using System.Windows.Forms;  using Microsoft.Win32; 
  5. using System.Drawing.Drawing2D;  using System.IO; 
  6. namespace WindowsApplication2  { 
  7. public partial class Form3 : Form  { 
  8. public Form3()  { 
  9. InitializeComponent();  this.FormBorderStyle = FormBorderStyle.None; 
  10. ColorConverter colorconvert = new ColorConverter();  this.BackColor = (Color)colorconvert.ConvertFromString("window"); 
  11. this.TransparencyKey = (Color)colorconvert.ConvertFromString("window");  } 
  12. private void button1_Click(object sender, EventArgs e)  { 
  13. this.Close();  } 
  14. protected override void OnPaint(PaintEventArgs e)  { 
  15. Graphics g = e.Graphics;  Rectangle mainRect = new Rectangle(0, 0, 695, 278); 
  16. Region mainRegion = new Region(mainRect);  e.Graphics.SetClip(mainRegion, CombineMode.Replace); 
  17. //设置窗体的外观形式  Point point1 = new Point(0, 32); 
  18. Point point2 = new Point(9, 20);  Point point3 = new Point(21, 13); 
  19. Point point4 = new Point(34, 9);  // 创建一个以点为元素的数组 
  20. Point[] curvePoints = { point1, point2, point3, point4 };  // 创建一个GraphicsPath 对象并添加一条曲线 
  21. GraphicsPath gPath = new GraphicsPath();  gPath.AddCurve(curvePoints, 0, 3, 0.8f); 
  22. gPath.AddLine(36, 9, 378, 9);  point1.X = 378; point1.Y = 9;