C#畫圓角矩形的方法
更新時(shí)間:2015年05月08日 15:18:10 作者:xujh
這篇文章主要介紹了C#畫圓角矩形的方法,涉及C#繪圖的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#畫圓角矩形的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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;
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
相關(guān)文章
C#開發(fā)Winform控件之打開文件對(duì)話框OpenFileDialog類
這篇文章介紹了C#開發(fā)Winform控件之打開文件對(duì)話框OpenFileDialog類,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02
C# WebApi+Webrtc局域網(wǎng)音視頻通話實(shí)例
這篇文章主要為大家詳細(xì)介紹了C# WebApi+Webrtc局域網(wǎng)音視頻通話實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07
C#實(shí)現(xiàn)的簡(jiǎn)單鏈表類實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)的簡(jiǎn)單鏈表類,涉及C#針對(duì)鏈表的定義、實(shí)現(xiàn)及鏈表節(jié)點(diǎn)的增加、刪除與修改技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
c# 通過內(nèi)存映射實(shí)現(xiàn)文件共享內(nèi)存的示例代碼
這篇文章主要介紹了c# 通過內(nèi)存映射實(shí)現(xiàn)文件共享內(nèi)存的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-04-04
C#觀察者模式(Observer Pattern)實(shí)例教程
這篇文章主要介紹了C#觀察者模式(Observer Pattern),主要以一個(gè)實(shí)例的形式講述了C#觀察者模式的實(shí)現(xiàn)過程,詳細(xì)講述了接口的定義、通知及動(dòng)作的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-09-09

