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

WinForm绘制圆角的方法

程序员文章站 2023-08-17 16:33:04
本文实例讲述了winform绘制圆角的方法。分享给大家供大家参考。具体实现方法如下: using system; using system.collection...

本文实例讲述了winform绘制圆角的方法。分享给大家供大家参考。具体实现方法如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using system.runtime.interopservices;
using system.drawing.drawing2d;
namespace appstartsample
{
 public partial class form3 : form
 {
  public form3()
  {
   initializecomponent();
  }
  private void button1_click(object sender, eventargs e)
  {
  }
  private void button2_click(object sender, eventargs e)
  {
  }
  public void setwindowregion()
  {
   system.drawing.drawing2d.graphicspath formpath;
   formpath = new system.drawing.drawing2d.graphicspath();
   rectangle rect = new rectangle(0, 22, this.width, this.height - 22);//
   formpath = getroundedrectpath(rect, 30);
   this.region = new region(formpath);
  }
  private graphicspath getroundedrectpath(rectangle rect, int radius)
  {
   int diameter = radius;
   rectangle arcrect = new rectangle(rect.location, new size(diameter, diameter));
   graphicspath path = new graphicspath();
   // 左上角  
   path.addarc(arcrect, 180, 90);
   // 右上角  
   arcrect.x = rect.right - diameter;
   path.addarc(arcrect, 270, 90);
   // 右下角  
   arcrect.y = rect.bottom - 0;
   path.addarc(arcrect, 0, 90);
   // 左下角  
   arcrect.x = rect.left;
   path.addarc(arcrect, 90, 90);
   path.closefigure();
   return path;
  }
  protected override void onresize(system.eventargs e)
  {
   this.region = null;
   setwindowregion();
  }
 }
}

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