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

Reading number is top 10 articles
PHP生成静态HTML文章发布系统的思路_php资料_编程技术
C#中ErrorProvider组件应用实例
结合ASP.NET与javascript开发电子沙盘_.net资料_编程技术
利用PHP和CSS改变网页文字大小_php资料_编程技术
PHP实例:用PHP实现多文件上载系统程序_[PHP教程]
用.NET,2.0压缩解压功能处理大型数据
PHP学习宝典-第二章 (续篇)_[PHP教程]
ASP.NET&Spring.NET&NHibernate最佳实践(六)——第3章人事子系统(3)_[Asp.Net教程]
GridView+FormView,示范数据:,新增、修改、删除(进阶篇:服务器控件)_[Asp.Net教程]
AspNetPager分页控件--使用方法_.net资料_编程技术
Reading number is top 10 pictures
Wild animals melee moment of life and death2
Absolutely shocked. National geographic 50 animal photographys7
狗狗与主人神同步2
Kim jong il's mistress, national beauty JinYuJi actor2
Startling Russian girl blind date scene1
yy365网站上的美女3
Beauty is thus produced
西方气质的东方美女3
The real super beauty10
生活中总有些低调的人,不经意间散发出土豪的气质
Download software ranking
美女写真1
Unix video tutorial15
Boxer vs Yellow3
变速齿轮3.26
Visual C++界面编程技术
The Bermuda triangle3
Tram sex maniac 2 (H) rar bag6
在线棋牌游戏3.05版
天龙八部最新服务端
C++编程教程第三版
qq published in(发表于) 2014/7/11 9:16:32 Edit(编辑)
c#中GDI+图形图像:GDI+中的区域使用方法

c#中GDI+图形图像:GDI+中的区域使用方法

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

GDI+中的区域

区域是输出设备显示区域的一部分,它可以是简单的(例如,单个矩形),也可以是复杂的(例如,多边形和闭合曲线的组合)。

区域常用于剪辑和命中检测。剪辑需要将要绘制的图形限制到显示区域的一个特定部分,通常是需要更新的部分,而命中检测则需要通过检查来确定按下鼠标时,光标是否在屏幕的特定区域中。

可以从矩形或路径中构造区域,也可以通过合并现有的区域来创建复杂区域。Region类提供以下区域合并方法:Intersect、Union、Xor、Exclude和Complement,其中,Intersect方法用来将Region对象更新为其自身与指定Region对象的交集,Union方法用来将Region对象更新为其自身与指定GraphicsPath(或Region)对象的并集,Xor方法用来将Region对象更新为其自身与指定GraphicsPath(或Region)对象的并集减去两者的交集,Exclude方法用来将Region对象更新为其自身与指定GraphicsPath(或Region)对象不相交的部分,Complement方法用来将Region对象更新为指定GraphicsPath(或Region)对象与此Region对象相交的部分。

两个区域的交集是同时属于这两个区域的所有点的集合。并集是属于一个或另一个或两个区域的所有点的集合。区域的补集是不在该区域的所有点的集合。

若要填充区域,需要有Graphics 对象、Brush对象和Region对象。Graphics对象提供FillRegion方法,该方法用来填充Region区域的内部,其语法格式如下:

public void FillRegion (

Brush brush,

Region region)

参数说明如下。

bursh:确定填充特性的Brush对象。

region:Region对象,表示要填充的区域。

示例

区域截取

本示例中,当程序运行时,单击【区域截取】按钮,截取窗体中的一组指定文本并显示出来。示例运行结果如图1所示。



图1 区域截取

Form1窗体中,单击【区域截取】按钮,首先在窗体中绘制一个多边形,然后声明Region类的一个对象,用来指定截取区域的大小;同时调用Graphics对象的SetClip方法,将该对象的剪辑区域设置为当前剪辑区域与指定Region对象的组合结果;最后调用Graphics对象的DrawString方法在窗体中绘制一组文本(该文本的一部分内容包含在截取区域中,另一部分不在其中)。【区域截取】按钮的Click事件代码如下:

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Point[] mypoints = {new Point(50, 20),new Point(120, 20), new Point(160, 80),new Point(50, 100)};

GraphicsPath mygraphicsPath = new GraphicsPath();

mygraphicsPath.AddPolygon(mypoints);

Region myregion = new Region(mygraphicsPath);

Pen mypen = new Pen(Color.Blue,2);

graphics.DrawPath(mypen, mygraphicsPath);

graphics.SetClip(myregion, CombineMode.Replace);

graphics.DrawString("GDI+区域", new Font(new FontFamily("楷体_GB2312"),36,

FontStyle.Regular,GraphicsUnit.Pixel), new SolidBrush(Color.Red), new PointF(40, 50));

}

注意:使用GraphicsPath类和CombineMode枚举时,需要添加using System.Drawing. Drawing2D命名空间。

完整程序代码如下:

★ ★★★★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_14

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Point[] mypoints = {new Point(50, 20),new Point(120, 20), new Point(160, 80),new Point(50, 100)};

GraphicsPath mygraphicsPath = new GraphicsPath();

mygraphicsPath.AddPolygon(mypoints);

Region myregion = new Region(mygraphicsPath);

Pen mypen = new Pen(Color.Blue,2);

graphics.DrawPath(mypen, mygraphicsPath);

graphics.SetClip(myregion, CombineMode.Replace);

graphics.DrawString("GDI+区域", new Font(new FontFamily("楷体_GB2312"),36,

FontStyle.Regular,GraphicsUnit.Pixel), new SolidBrush(Color.Red), new PointF(40, 50));

}

}

}

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

namespace _6_14

{

partial class Form1



添加到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.