当前位置: 首页 > 编程笔记 >

C#画圆角矩形的方法

红智鑫
2023-03-14
本文向大家介绍C#画圆角矩形的方法,包括了C#画圆角矩形的方法的使用技巧和注意事项,需要的朋友参考一下

本文实例讲述了C#画圆角矩形的方法。分享给大家供大家参考。具体实现方法如下:

protected void Page_Load(object sender, EventArgs e)
{
 Bitmap bm = new Bitmap(800, 600);
 Graphics g = Graphics.FromImage(bm);
 g.FillRectangle(Brushes.White,new Rectangle(0,0,800,600));
 FillRoundRectangle(g,Brushes.Plum,new Rectangle(100, 100, 100, 100), 8);
 DrawRoundRectangle(g, Pens.Yellow,new Rectangle(100, 100, 100, 100), 8);
 bm.Save(Response.OutputStream, ImageFormat.Jpeg);
 g.Dispose();
 bm.Dispose();
}
public static void DrawRoundRectangle(Graphics g,Pen pen,Rectangle rect, int cornerRadius)
{
 using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
 {
  g.DrawPath(pen, path);
 }
}
public static void FillRoundRectangle(Graphics g, Brush brush,Rectangle rect, int cornerRadius)
{
 using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
 {
  g.FillPath(brush, path);
 }
}
internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
{
 GraphicsPath roundedRect = new GraphicsPath();
 roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
 roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
 roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
 roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
 roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
 roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
 roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
 roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
 roundedRect.CloseFigure();
 return roundedRect;
}

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

 类似资料:
  • 本文向大家介绍Android实现圆角矩形和圆形ImageView的方式,包括了Android实现圆角矩形和圆形ImageView的方式的使用技巧和注意事项,需要的朋友参考一下 Android中实现圆角矩形和圆形有很多种方式,其中最常见的方法有ImageLoader设置Option和自定义View。 1.ImageLoader加载图片 ImageLoader.getInstance().displa

  • 问题内容: 我发现只能填充矩形,而没有圆角,该怎么办? 问题答案: HTML5画布没有提供绘制带有圆角的矩形的方法。 如何使用和方法? 您也可以使用方法代替方法。

  • 本文向大家介绍js绘制圆形和矩形的方法,包括了js绘制圆形和矩形的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了js绘制圆形和矩形的方法。分享给大家供大家参考。具体如下: 这里使用js来绘制圆形和矩形,支持选择图形的背景颜色,同时可设置圆角矩形、半径、正圆、矩形、正方形这几个选项。或许这些图形你不需要,但重要的是让你学会JavaScript绘制图形的方法,这是要表达的核心。 运行效果

  • 主要内容:圆角矩形,椭圆示例JavaFX Shape类定义了常见的形状,例如线,矩形,圆,Arc,CubicCurve,Ellipse和QuadCurve。 在场景图上绘制矩形需要宽度,高度和左上角的(,)位置。 要在JavaFX中绘制一个矩形,可以使用类。 上面的代码生成以下结果。 圆角矩形 类实现了弧宽和弧高。可以使用这些功能来绘制圆角矩形。 上面的代码生成以下结果。 椭圆示例 上面的代码生成以下结果。

  • 本文向大家介绍详解微信小程序canvas圆角矩形的绘制的方法,包括了详解微信小程序canvas圆角矩形的绘制的方法的使用技巧和注意事项,需要的朋友参考一下 微信小程序允许对普通元素通过 border-radius 的设置来进行圆角的绘制,但有时候在使用 canvas 绘图的时候,也需要圆角,例如需要将页面上某块区域导出为图片下载到本地的时候,常用的解决方法就是使用 canvas 将这块区域绘制出来

  • 本文向大家介绍刻在椭圆上的矩形内切三角形的面积?,包括了刻在椭圆上的矩形内切三角形的面积?的使用技巧和注意事项,需要的朋友参考一下 为了理解这个复杂的问题,让我们分两部分进行。首先,我们将找到矩形的尺寸,并根据该尺寸找到内接的三角形的面积。 使用椭圆和微分方程,矩形面积的数学公式为:  面积= 2ab, 其中2a =长轴,2b =短轴。 可以内接在矩形中的最大三角形应位于相同的基座上,并且在矩形的

  • 本文向大家介绍C#使用GDI画圆的方法,包括了C#使用GDI画圆的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了C#使用GDI画圆的方法。分享给大家供大家参考。具体实现方法如下: 希望本文所述对大家的C#程序设计有所帮助。

  • 本文向大家介绍iOS实现圆角箭头矩形的提示框,包括了iOS实现圆角箭头矩形的提示框的使用技巧和注意事项,需要的朋友参考一下 先来看看我们见过的一些圆角箭头矩形的提示框效果图 一、了解CGContextRef 首先需要对 CGContextRef 了解, 作者有机会再进行下详细讲解, 这篇中简单介绍下, 方便后文阅读理解. 先了解 CGContextRef 坐标系 坐标系 举例说明 : 对于 商城类