您的位置:首页 > 其它

打造属于自已的图形(一) 绘图基础

2008-12-12 00:34 357 查看
作者: furenjun

本文内容:

一. 认识 System.Drawing类

二 了解GDI

三. 掌握常用的绘图方法

3.1 绘制一些简单的图形

3.2 绘制一个多色的矩形

3.3 绘制一个渐变的矩形

3.4 绘制一个多色渐变的矩形

四. 应用本文学到的方法打造属于自已的第一批图形

4.1 电子屏效果

4.2 霓虹灯效果

4.3 进度条显示效果

前言

用惯了别人做的图形控件,常常感慨别人做得好,心中徒生羡慕。

何时自已也能做出变幻莫测的图形效果呢?

想想.Net 对图形支持功能非常丰富,何不自已动手打造呢?!

好了,闲话少说,开始我们打造自已的图形之旅吧.
本文的结尾提供完整源码下载.

一.认识 System.Drawing类

Code

private void drawGraphicsPath()

{

Graphics g = this.pictureBox7.CreateGraphics();

g.Clear(this.pictureBox7.BackColor );

//消除锯齿

g.SmoothingMode = SmoothingMode.AntiAlias;

//高质量,低速度绘制

g.CompositingQuality = CompositingQuality.HighQuality;

StringFormat mySF = new StringFormat();

mySF.Alignment = StringAlignment.Near;

mySF.LineAlignment = StringAlignment.Center;

mySF.FormatFlags = StringFormatFlags.NoWrap;

SizeF strSize = g.MeasureString(PercentStr, PercFont, new PointF(), mySF);

int strWidth = (int)(strSize.Width + 10);

GraphicsPath myPath = new GraphicsPath();

int fontStyle = (int)FontStyle.Bold;

int x = (int)((this.pictureBox7.Width - strWidth) / 2);

int y = (int)((this.pictureBox7.Height - strSize.Height) / 2);

Point origin = new Point(x, y + 5);

StringFormat format = StringFormat.GenericDefault;

// Add the string to the path.

myPath.AddString(PercentStr,

family2,

fontStyle,

emSize2,

origin,

format);

GraphicsPath stringPath = myPath;

CurrentX += this.pictureBox7.Width / 10;

Rectangle blotoutRect = new Rectangle(0, 0, CurrentX, this.pictureBox7.Height);

myPath.AddRectangle(blotoutRect);

//Draw the path to the screen.

g.FillPath(Brushes.Green, myPath);

}

本文源程序下载:

打造属于自已的图形(一) 源码

打造透明的可移动的图形窗体 源码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: