欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

winform创建不规则窗体的方法

程序员文章站 2023-11-18 21:14:16
本文实例讲述了winform创建不规则窗体的方法。分享给大家供大家参考。具体如下: using system; using system.collections...

本文实例讲述了winform创建不规则窗体的方法。分享给大家供大家参考。具体如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using microsoft.win32;
using system.drawing.drawing2d;
using system.io;
namespace windowsapplication2
{
 public partial class form3 : form
 {
  public form3()
  {
   initializecomponent();
   this.formborderstyle = formborderstyle.none;
   colorconverter colorconvert = new colorconverter();
   this.backcolor = (color)colorconvert.convertfromstring("window");
   this.transparencykey = (color)colorconvert.convertfromstring("window");
  }
  private void button1_click(object sender, eventargs e)
  {
   this.close();
  }
  protected override void onpaint(painteventargs e)
  {
   graphics g = e.graphics;
   rectangle mainrect = new rectangle(0, 0, 695, 278);
   region mainregion = new region(mainrect);
   e.graphics.setclip(mainregion, combinemode.replace);
   //设置窗体的外观形式
   point point1 = new point(0, 32);
   point point2 = new point(9, 20);
   point point3 = new point(21, 13);
   point point4 = new point(34, 9);
   // 创建一个以点为元素的数组
   point[] curvepoints = { point1, point2, point3, point4 };
   // 创建一个graphicspath 对象并添加一条曲线
   graphicspath gpath = new graphicspath();
   gpath.addcurve(curvepoints, 0, 3, 0.8f);
   gpath.addline(36, 9, 378, 9);
   point1.x = 378; point1.y = 9;
   point2.x = 387; point2.y = 5;
   point3.x = 394; point3.y = 0;
   point[] curvepoints2 = { point1, point2, point3 };
   gpath.addcurve(curvepoints2, 0, 2, 0.8f);
   gpath.addline(394, 0, 0, 0);
   region rg = new region(gpath);
   e.graphics.excludeclip(rg);
  //可以为任意图片
   string str = directory.getcurrentdirectory() + "\\2.png";
   image img = image.fromfile(str);
   e.graphics.drawimage(img, 0, 0, 695, 278);
   // 重设剪切好的区域
   e.graphics.resetclip();
  }
 }
}

希望本文所述对大家的c#程序设计有所帮助。