All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
DB2,9和ASP.NET2.0构建下一代应用程序之二_[Asp.Net教程]
在Asp.Net2.0中可以方便的访问配置文件web.config_[Asp.Net教程]
Asp.net,Ajax,学习笔记2,UpdatePanel的使用(上)_[Asp.Net教程]
PHP技巧:php技术生成静态页面的实现_[PHP教程]
关于C#静态构造函数的几点说明_.net资料_编程技术
C#中国身份证验证(包括省份验证和校验码验证,符合GB11643-1999标准)_[Asp.Net教程]
ASP.NET,2.0,页面状态持续程序实例_[Asp.Net教程]
.net下访问Access数据库需要注意的问题_[Asp.Net教程]
技巧:.NET中加密与解密QueryString的方法_.net资料_编程技术
C#中SplitContainer控件应用实例
Reading number is top 10 pictures
含苞欲放的素颜美少女2
Chinese paper-cut grilles art appreciation8
Play for Free show breast in a world of ice and snow
Female model behind the bitterness, often being overcharged5
这才叫绝色美女1
Discharge accidentally Actresses by the breast4
农夫山泉变身记
这玉米,买还是不卖?
擦地板的大叔太好了
Absolutely shocked. National geographic 50 animal photographys6
Download software ranking
Boxer's Top ten classic battle9
Eclipse-CALMSANNY (second edition)
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
传奇私服架设教程
Rio big adventure
I'm come from Beijing1
I'm come from Beijing2
Tram sex maniac 2 (H) rar bag13
VC++6.0培训教程
软件工程思想
qq published in(发表于) 2014/7/11 9:16:34 Edit(编辑)
c#中GDI+图形图像:GDI+中的图形路径使用方法

c#中GDI+图形图像:GDI+中的图形路径使用方法

c#中GDI+图形图像:GDI+中的图形路径使用方法|实例

GDI+中的图形路径

路径是通过组合直线、矩形和简单的曲线而形成的。在GDI+中,GraphicsPath对象允许将基本构造块收集到一个单元中,调用一次Graphics类的DrawPath方法,就可以绘制出整个单元的直线、矩形、多边形和曲线。

GraphicsPath类提供了下列方法来创建要绘制的图形路径:AddLine、AddRectangle、AddEllipse、AddArc、AddPolygon、AddCurve(针对基数样条)和AddBezier。这些方法中的任何一种都是可重载的,即每种方法都支持几个不同的参数列表。例如,AddLine方法的一种格式接收4个整数,而其另一种格式则接收两个Point对象。

将直线、矩形和贝塞尔样条添加到路径的方法具有多个伴随方法,这些伴随方法在一次调用中将多个项添加到路径。伴随方法包括AddLines、AddRectangles和AddBeziers。同样,AddCurve和AddArc方法也有将闭合曲线或扇形添加到路径的伴随方法。例如,AddClosedCurve和AddPie。

若要绘制路径,需要Graphics对象、Pen对象和GraphicsPath对象。Graphics对象提供DrawPath方法,Pen对象存储用于呈现路径的线条属性,如宽度和颜色,而GraphicsPath对象存储构成路径的直线和曲线序列。Pen对象和GraphicsPath对象作为参数传递给DrawPath方法。

DrawPath方法用来绘制GraphicsPath图形路径,其语法格式如下:

public void DrawPath (

Pen pen,

GraphicsPath path)

参数说明如下。

pen:Pen对象,它确定路径的颜色、宽度和样式。

path:要绘制的GraphicsPath图形路径。

示例

绘制图形路径

本示例中,当程序运行时,单击【绘制图形路径】按钮,在窗体中根据条件绘制指定的图形路径。示例运行结果如图1所示。



图1 绘制图形路径

Form1窗体中,在【绘制图形路径】按钮的Click事件中分别声明Graphics类、GraphicsPath类和Pen类的3个实例对象,然后声明一个Point结构数组,用来定义基数样条的各顶点,同时调用GraphicsPath对象的AddArc方法、AddCurve方法、AddString方法和AddPie方法,增加图形路径,最后调用Graphics对象的DrawPath方法在窗体中绘制指定的图形路径。【绘制图形路径】按钮的Click事件代码如下:

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

GraphicsPath myGraphicsPath = new GraphicsPath();

Pen myPen = new Pen(Color.Blue, 1);

Point[] myPoints = { new Point(15, 30), new Point(30, 40), new Point(50, 30) };

myGraphicsPath.AddArc(15, 20, 80, 50, 210, 120);

myGraphicsPath.StartFigure();

myGraphicsPath.AddCurve(myPoints);

myGraphicsPath.AddString("图形路径",new FontFamily("华文行楷"),(int)FontStyle.Underline,50,new PointF

(20,50),new StringFormat());

myGraphicsPath.AddPie(180, 20, 80, 50, 210, 120);

graphics.DrawPath(myPen, myGraphicsPath);

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace _6_08

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

GraphicsPath myGraphicsPath = new GraphicsPath();

Pen myPen = new Pen(Color.Blue, 1);

Point[] myPoints = { new Point(15, 30), new Point(30, 40), new Point(50, 30) };

myGraphicsPath.AddArc(15, 20, 80, 50, 210, 120);

myGraphicsPath.StartFigure();

myGraphicsPath.AddCurve(myPoints);

myGraphicsPath.AddString("图形路径", new FontFamily("华文行楷"), (int)FontStyle.Underline, 50, new PointF(20, 50), new StringFormat());

myGraphicsPath.AddPie(180, 20, 80, 50, 210, 120);

graphics.DrawPath(myPen, myGraphicsPath);

}

}

}

★ ★★★★Form1.Designer.cs窗体设计文件完整程序代码★★★★★

namespace _6_08

{

partial class Form1

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.