跟我学VS#语言编程技术——C#语言中的图形编程应用技术及示例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.1跟我学VS#语言编程技术——C#语言中的图形编程应用技术及示例
1.1.1C#语言中的图形编程应用技术及示例
1、图形类所在的命名空间
主要采用.Net中的System.Drawing,更高级的函数则包含在System.Drawing.Drawing2D、System.Drawing.Imaging、System.Drawing.Text等命名空间中。

2、Graphics对象
它采用面向对象的封装机制,包含指定要在屏幕上作图的各个属性,类似于VC++6.0中的窗口上下文设备,但与它又有差别(没有将Pen、Brush、Path、Image、Font等对象捆绑),这些对象是独立于Graphics对象的,它们为Graphics类中的图形方法的参数。

从而简化了图形编程。

3、图形编程的方法
由于Graphics对象封装了GDI+(VC#中的,而VC++.Net中为GDI方式)界面画图方法和图形显示设备,不必完成获得设备句柄、装载句柄、保存和恢复句柄等工作。

而只需通过事件参数PaintEventArgs、MouseEventAgrs来创建一个Graphics对象的实例或直接通过Graphics对象调用相应的图形方法来作图。

4、图形编程中常用的几个结构
(1)Rectangle结构体
主要有左上角的x与y及width、height等四个属性(存储矩形区域的位置和大小)。

并且可以对它进行“==”(测试两个 Rectangle 结构的位置和大小是否相同)、“!=”等比较操作。

RectangleF结构体代表浮点数类型。

(2)Size结构体
主要有width、height等两个属性(用宽度和高度的有序对表示矩形区域的大小)。

SizeF 结构体代表浮点数类型。

并且可以实现Size到Point((Point)Size)、Size到SizeF((SizeF)Size)的转换。

(3)Point结构体
主要有x与y两个属性(表示在二维平面中定义点的整数x和y坐标的有序对)。

并且
可以对它进行“==”、“!=”等比较操作。

5、图形编程中常见的属性类
(1)Pen 画笔类
它主要指定线宽和线的模式。

Pen 对象绘制具有指定宽度和样式的直线和曲线。

使用DashStyle 属性绘制不同的虚线。

由 Pen 对象绘制的直线可用各种填充模式(包括纯色和纹理)填充。

填充模式取决于Brush画刷或用作填充对象的纹理。

分别可以采用Brush、Color、及Brush、width和Color、width来创建一个画笔。

Pen myPen=new Pen(Color.Black, 3); //创建一个3个像素宽的黑色画笔
myPen.DashStyle=DashStyle.Dot;//并指定由点构成的虚直线画笔。

(2)Brush画刷类
它主要指定填充区域的颜色和样式。

画刷主要有几种风格:实心画刷(SolidBrush,用单一颜色填充)、网格画刷(HatchBrush,用交叉网格填充)、空画刷(不填充)等。

如果要创建这些画刷,可以分别采用如下的子类的实例来实现:HatchBrush(网格)、LinearGradientBrush(线性渐变,封装双色渐变和自定义多色渐变)、PathGradientBrush(它是从路径的中点到路径的外边界边缘的平滑的彩色渐变。

)、SolidBrush(单色画刷)、TextureBrush(画纹画刷,使用图像来填充)。

如:
1)SolidBrush drawBrush=new SolidBrush(Color.Black); //创建一个黑色的画刷
2)HatchBrush myBrush=new HatchBrush(HatchStyle.Vertical,Color.Red,Color.Black);//方向,前景色,背景色
3)Image myImg=Image.FromFile(String filename) ;
TextureBrush textureBrush=new TextureBrush(myImg); //使用指定的图象作为画刷
(3)Color颜色类
它主要指定图形的颜色,是ARGB格式。

可以采用:
1)Color.FromArgb()方法
从四个8 位ARGB 分量(alpha--- alpha值默认为 255(完全不透明)、红色、绿色和蓝色)值创建Color对象。

如:
SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0));
2)Color.FromName()方法
根据预定义颜色的指定名称来创建一个Color类对象。

有效名称与KnownColor 枚举的元素名称相同。

如:
Color mycolor=Color.FromName("Blue");
(4)Font字体类
它主要指定系统中的字体。

可以采用如下方式创建出新的字体。

Font drawFont=new Font("Arial",16); //字体名为“Arial”,大小为16磅
由于Font 对象是不可变的(一旦创建出将无法调整它的任何属性),只能给控件的Font 属性分配一个新Font 对象。

但可以采用如下方法使新的字体基于现有字体。

myControl.Font = new Font(myControl.Font, myControl.Font.Style | FontStyle.Bold);
编程要点:
常见的几种字形为FontStyle.Bold 粗体,FontStyle.Italic 斜体,FontStyle.Regular 正常体,FontStyle.Strikeout 带删除线的文字,FontStyle.Underline 带下划线的文字。

(5)Image类
Image.FromFile(String filename) 方法,以实现从指定的文件中创建Image 对象。

并返回所创建的Image 对象。

Bitmap位图类:它表示一个矩形图形并可以显示图片,也可以从指定的文件中初始化Bitmap 类的对象。

6、Graphics类常用的画图方法(注意它们都有重载方法以实现以不同的参数画出同一种图形)
(1)点
DrawLine()画线(两个Point对象并且为同一个点时)。

(2)线
DrawLine()画线(两个Point对象)、DrawLines()画线段(Point的数组)、DrawArc()画椭圆弧(X、Y、Width、Height、StartAngle、ArcAngle)、DrawClosedCurve()画封闭的曲线(Point的数组)、DrawCurve()画曲线(Point的数组)、FillClosedCurve()画添充封闭的曲线(Point的数组)。

(3)面
DrawRectangle()和FillRectangle()画矩形和添充矩形(X、Y、Width、Height )、DrawPolygon()
和FillPolygon()画多边形和添充多边形(Point的数组)、DrawEllipse()和FillEllipse()画椭圆和添充椭圆(X、Y、Width、Height )、DrawPie()和FillPie() 画椭圆饼和添充椭圆饼(X、Y、Width、Height )。

(4)其它
DrawImage()画图像(X、Y并采用原始的大小)、DrawString()画字符串(Font、Brush、X、Y)、Clear() 清除图形区域、Dispose() 释放Graphics对象所占用的资源。

7、利用Graphics对象画图例:以下为在控件的Paint()方法内(PaintEventArgs e)
(1)画线
例1,画一般的直线:Pen myPen=new Pen(myBrush,2);
g.DrawLine(myPen,new Point(this.Top,this.Left),new Point(this.Right,this.Bottom));
例2,画虚直线:Pen myPen=new Pen(Color.Blue,2);
myPen.DashStyle=DashStyle.Dash;
g.DrawLine(myPen,100,50,300,80);
例3,画椭圆弧线:
g.DrawArc(myPen, 100,50,100,70,30,180); 起始角度为30度,弧度为180度
例4,画曲线:
int offset = 2; int numSegments = 4; float tension = 1.0F;
e.Graphics.DrawCurve(greenPen, curvePoints, offset, numSegments, tension);
(2)画面
例1,画椭圆:g.DrawEllipse(myPen,0,0,this.Width, this.Height); 或可以:
Rectangle myRect=new Rectangle(100,100,200,200);
g.DrawEllipse(myPen,myRect);
例2,画多边形:Point []myPointArray={new Point(0,0),new Point(50,30),new Point(30,60)}; //定义出多边形所在的各个顶点数组
g.DrawPolygon(myPen,myPointArray);//画出该多边形(其中myPen指定线宽和颜色)(3)画图像或位图
GDI+提供了Image和Bitmap类来实现画图像或位图,其中Image类负责装载和保存图像,Bitmap类(支持多种图像格式,如*.gif、*.jpeg、*.bmp、*.png、*.tif)从Image类派生出,
将图像转换为GDI+的标准格式以实现在像素级控制图像。

例1:画图像
Bitmap myBitmap=new Bitmap("Climber.jpg"); //加载指定的图像文件
g.DrawImage(myBitmap,x,y); //然后在指定的位置上画出该图像
例2:Bitmap类有一个Clone()方法可以实现对图像的复制,通过指定原矩形以指定想要拷贝的源图像区域,实现对图像的复制。

Bitmap originalBitmap=new Bitmap("soda.gif"); //生成原图像
Rectangle sourceRectangle=new Rectangle(0,0,originalBitmap.Width,
originalBitmap.Height); //指定想要拷贝的源图像区域Bitmap copyBitmap=originalBitmap.Clone(sourceRectangle,
PixelFormat.DontCare); //拷贝源图像区域
g.DrawImage(originalBitmap,10,10);
g.DrawImage(copyBitmap,100,10); //分别画出原图像与复制后的图像
(4)写文字
String drawString="Sample Text !";
Font myFont=new Font("Arial",16); //定义自己的字体对象(指定字体名及大小)
SolidBrush drawBrush=new SolidBrush(Color.Black); //定义画刷
StringFormat drawFormat=new StringFormat();
drawFormat.FormatFlags=StringFormatFlags.DirectionVertical; //产生垂直方向的文字
g.DrawString(drawString,myFont,drawBrush,100,100,drawFormat);
编程要点:
StringFormatFlags枚举定义文字的格式,如成员DirectionRightToLeft可指定文本从右到左排列。

8、Regions区域的使用
(1)Regions
区域是屏幕的一部分,它可以简单得象矩形,也可以复杂得象多边形和封闭曲线的合成。

(2)主要的作用
Regions区域经常用来剪切和碰撞测试。

其中剪切包括限制画图到一个特定的屏幕上(需
要更新的区域),应用程序可以使用若干区域来堆砌绘图操作的输出,窗口管理器则使用区域来定义窗口的绘制区域;碰撞测试包括检查当鼠标被按下时光标是否在给定的区域内,或检查一个点或矩形是否与某个区域相交。

(3)创建Regions区域的方法
可以采用Rectangle对象、Path对象或Region数据的字节数据作为Region的构造函数来创建它,也可以合成已有的Region来创建复杂的Region。

可以采用Intersect交集(同时属于两个区域的所有点集)、Union并集(属于两个区域中的任何区域的点集)、Complement补充(不属于两个区域的所有点集)、Xor异或(两个区域异或运算,挖空交集的区域)、Exclude 排除(两个区域的点乘运算,一个区域去掉两者相重合的区域)。

Rectangle rect1=new Rectangle(10,10,200,200);
Rectangle rect2=new Rectangle(50,50,300,300);
Region region1=new Region(rect1);
Region region2=new Region(rect2); //分别基于不同的矩形来创建出区域
region1.Intersect(region2); //对它们进行交集运算以创建出新的区域SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillRegion(myBrush, myRegion); //填充该新区域
9、Paths 路径的使用
(1)Paths
它是由合成线、矩形和简单的弧线等基本的图形所形成的统一的单元并可以采用DrawPath()一次性地画出,path不必非要连接起来。

(2)创建Paths
利用Paths类创建出一个Path,然后调用AddLine()、AddRectangle()、AddEllipse()、AddArc()等方法添加基本的图形到path中。

Paths myPath=new Paths();
myPath.AddLine(0,0,30,20);
myPath.AddEllipse(20,20,20,40);
myPath.AddPath(myPath2,false); //可以将一个path添加到另一个path中
myPath.AddString("Path String",myFontFamily,0,24,myPointF, myStringFormat); //可以将一个
字符串添加到path中
myPath.AddPie(230,10,40,40,40,110); //可以将圆饼添加到path中
g.DrawPath(myPen, myPath);
(3)GraphicsPath类:它属于System.Drawing2D的命名空间中。

GraphicsPath graphPath = new GraphicsPath();
graphPath.AddEllipse(0, 0, 200, 100);
Pen blackPen = new Pen(Color.Black, 3);
g.DrawPath(blackPen, graphPath);
10、应用实例:画图工具程序的设计
(1)界面设计
设计一个Form、MainMenu(包含调色、选图、选择画图参数等菜单项目)。

然后分别设计它的各个菜单的事件。

(2)代码设计,并编程其各个菜单的事件响应函数
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using ponentModel;
using System.Windows.Forms;
using System.Data;
//using System.Reflection;
namespace WinApp{
using System.Drawing;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : Form{
private Image img;
private bool slatOut=false;
private ponentModel.IContainer components; private Timer time1 = new Timer();
private Rectangle rect = new Rectangle(100,100,130,70); private System.Windows.Forms.PictureBox Playing; private System.Windows.Forms.PictureBox Circle; private System.Windows.Forms.PictureBox CDAudio; private System.Windows.Forms.PictureBox smBut; private System.Windows.Forms.PictureBox stopBut; Point pt = new Point(200,100);
private bool blnMoving = false;
private int MouseDownX;
private bel disp;
private System.Windows.Forms.Button Ex;
private int MouseDownY;
private bool playFlg=false;
private ArrayList imgList = new ArrayList();
private bel tm;
private System.Windows.Forms.PictureBox animatPicture; private int cnt = -1;
public Form1(){
time1.Interval = 100;
time1.Enabled = true;
time1.Tick += new EventHandler(time1_Tick);
img = new Bitmap("mediaPlayer.jpg");
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.CDAudio.Image = System.Drawing.Bitmap.FromFile("CDAudio.jpg");
this.Playing.Image = System.Drawing.Bitmap.FromFile("PlayingUp.jpg");
this.Circle.Image = System.Drawing.Bitmap.FromFile("Circle.jpg");
this.smBut.Image = System.Drawing.Bitmap.FromFile("buttonNormal.jpg");
this.stopBut.Image = System.Drawing.Bitmap.FromFile("stopButNormal.jpg");
Application.ApplicationExit += new EventHandler(Form_OnExit);
// Application.AddMessageFilter(msgFilter);
}
private void ToolBar_Clicked(object sender, ToolBarButtonClickEventArgs e) { MessageBox.Show(e.Button.ToolTipText);
}
private void HelpAbout_Clicked(object sender, EventArgs e){
MessageBox.Show("The amazing menu app ...");
}
private void FileExit_Clicked(object sender, EventArgs e){
this.Close();
}
private void Form_OnExit(object sender, EventArgs evArgs) {
}
private void GetStats(){
MessageBox.Show(Application.StartupPath, "I live here...");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing ){
if( disposing ){
if (components != null){
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.smBut = new System.Windows.Forms.PictureBox();
this.CDAudio = new System.Windows.Forms.PictureBox();
this.disp = new bel();
this.Ex = new System.Windows.Forms.Button();
this.Playing = new System.Windows.Forms.PictureBox();
this.Circle = new System.Windows.Forms.PictureBox();
this.animatPicture = new System.Windows.Forms.PictureBox();
this.stopBut = new System.Windows.Forms.PictureBox();
this.tm = new bel();
this.SuspendLayout();
//
// smBut
//
this.smBut.Location = new System.Drawing.Point(473, 100);
= "smBut";
this.smBut.Size = new System.Drawing.Size(17, 33);
this.smBut.TabIndex = 6;
this.smBut.TabStop = false;
this.smBut.Click += new System.EventHandler(this.smBut_Click);
this.smBut.MouseEnter += new System.EventHandler(this.smBut_MouseEnter);
this.smBut.MouseLeave += new System.EventHandler(this.smBut_MouseLeave);
//
// CDAudio
//
this.CDAudio.Location = new System.Drawing.Point(4, 108);
= "CDAudio";
this.CDAudio.Size = new System.Drawing.Size(88, 40);
this.CDAudio.TabIndex = 4;
this.CDAudio.TabStop = false;
this.CDAudio.Click += new System.EventHandler(this.pictureBox1_Click);
this.CDAudio.MouseEnter += new System.EventHandler(this.CDAudio_MouseEnter);
this.CDAudio.MouseLeave += new System.EventHandler(this.CDAudio_MouseLeave);
//
// disp
//
this.disp.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.disp.BackColor = System.Drawing.Color.Black;
this.disp.ForeColor = System.Drawing.Color.Lime;
this.disp.Location = new System.Drawing.Point(204, 196);
= "disp";
this.disp.Size = new System.Drawing.Size(156, 18);
this.disp.TabIndex = 8;
// Ex
//
this.Ex.BackColor = System.Drawing.Color.LightGray;
this.Ex.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Ex.ForeColor = System.Drawing.Color.Black;
this.Ex.Location = new System.Drawing.Point(440, 8);
= "Ex";
this.Ex.Size = new System.Drawing.Size(14, 14);
this.Ex.TabIndex = 5;
this.Ex.Text = "X";
this.Ex.Click += new System.EventHandler(this.button1_Click_1);
this.Ex.MouseEnter += new System.EventHandler(this.Ex_MouseEnter);
this.Ex.MouseLeave += new System.EventHandler(this.Ex_MouseLeave);
//
// Playing
//
this.Playing.Location = new System.Drawing.Point(4, 68);
= "Playing";
this.Playing.Size = new System.Drawing.Size(88, 40);
this.Playing.TabIndex = 2;
this.Playing.TabStop = false;
this.Playing.Click += new System.EventHandler(this.Playing_Click);
this.Playing.MouseEnter += new System.EventHandler(this.Playing_MouseEnter);
this.Playing.MouseLeave += new System.EventHandler(this.Playing_MouseLeave);
//
// Circle
this.Circle.Location = new System.Drawing.Point(109, 200);
= "Circle";
this.Circle.Size = new System.Drawing.Size(68, 68);
this.Circle.TabIndex = 3;
this.Circle.TabStop = false;
this.Circle.Click += new System.EventHandler(this.Circle_Click);
this.Circle.MouseEnter += new System.EventHandler(this.Circle_MouseEnter);
this.Circle.MouseLeave += new System.EventHandler(this.Circle_MouseLeave);
//
// animatPicture
//
this.animatPicture.BackColor = System.Drawing.Color.Black;
this.animatPicture.Location = new System.Drawing.Point(128, 40);
= "animatPicture";
this.animatPicture.Size = new System.Drawing.Size(280, 136);
this.animatPicture.TabIndex = 10;
this.animatPicture.TabStop = false;
this.animatPicture.Tag = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
//
// stopBut
//
this.stopBut.Location = new System.Drawing.Point(180, 220);
= "stopBut";
this.stopBut.Size = new System.Drawing.Size(36, 49);
this.stopBut.TabIndex = 7;
this.stopBut.TabStop = false;
this.stopBut.Click += new System.EventHandler(this.stopBut_Click);
this.stopBut.MouseEnter += new System.EventHandler(this.stopBut_MouseEnter);
this.stopBut.MouseLeave += new System.EventHandler(this.stopBut_MouseLeave);
//
// tm
//
this.tm.BackColor = System.Drawing.Color.Black;
this.tm.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(255)), ((System.Byte)(128)));
this.tm.Location = new System.Drawing.Point(352, 196);
= "tm";
this.tm.Size = new System.Drawing.Size(72, 18);
this.tm.TabIndex = 9;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Silver;
this.ClientSize = new System.Drawing.Size(658, 605);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.animatPicture,
this.tm,
this.disp,
this.stopBut,
this.smBut,
this.Ex,
this.CDAudio,
this.Circle,
this.Playing});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
= "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.TransparencyKey = System.Drawing.Color.Silver;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form_Paint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void Form_Paint(object sender, PaintEventArgs e){
Graphics g = e.Graphics;
Rectangle mainRect = new Rectangle(0, 0, 695, 278);
Region mainRegion = new Region(mainRect);
e.Graphics.SetClip(mainRegion, CombineMode.Replace);
Point point1 = new Point(0, 32);
Point point2 = new Point(9, 20);
Point point3 = new Point(21, 13);
Point point4 = new Point(34, 9);
// Create an array of the points.
Point[] curvePoints = { point1, point2, point3, point4 };
// Create a GraphicsPath object and add a curve.
GraphicsPath myPath = new GraphicsPath();
myPath.AddCurve(curvePoints, 0, 3, 0.8f);
myPath.AddLine(36, 9, 378, 9);
point1.X=378;point1.Y=9;
point2.X=387;point2.Y=5;
point3.X=394;point3.Y=0;
Point[] curvePoints2 = { point1, point2, point3 };
myPath.AddCurve(curvePoints2, 0, 2, 0.8f);
myPath.AddLine(394, 0, 0, 0);
Region ExcludeRegion3 = new Region(myPath);
e.Graphics.ExcludeClip(ExcludeRegion3);
//left bottom
GraphicsPath myPath3 = new GraphicsPath();
point1.X=0;point1.Y=180;
point2.X=19;point2.Y=198;
point3.X=62;point3.Y=204;
point4.X=83;point4.Y=221;
Point point5 = new Point(93, 248);
Point point6 = new Point(102, 267);
Point point7 = new Point(125, 278);
Point[] curvePoints3 = { point1, point2, point3, point4, point5, point6, point7 };
myPath3.AddCurve(curvePoints3, 0, 6, 0.8f); myPath3.AddLine(125, 278, 90, 300);
myPath3.AddLine(90, 300, 0, 300);
Region ExcludeRegion2 = new Region(myPath3);
e.Graphics.ExcludeClip(ExcludeRegion2);
point1.X=454;point1.Y=0;
point2.X=470;point2.Y=12;
point3.X=481;point3.Y=34;
Point[] curvePoints4 = { point1, point2, point3 }; GraphicsPath myPath2 = new GraphicsPath(); myPath2.AddCurve(curvePoints4, 0, 2, 0.8f); myPath2.AddLine(481, 30, 481, 76);
myPath2.AddLine(481, 76, 495, 76);
myPath2.AddLine(495, 76, 495, 0);
Region ExcludeRegion4 = new Region(myPath2);
e.Graphics.ExcludeClip(ExcludeRegion4);
// right side
GraphicsPath myPath5 = new GraphicsPath(); point1.X=481;point1.Y=76;
point2.X=494;point2.Y=115;
point3.X=481;point3.Y=158;
Point[] curvePoints5 = { point1, point2, point3 }; myPath5.AddCurve(curvePoints5, 0, 2, 0.8f); myPath5.AddLine(481, 158, 481, 279);
myPath5.AddLine(481, 255, 495, 279);
myPath5.AddLine(495, 279, 495, 0);
Region ExcludeRegion6 = new Region(myPath5);
e.Graphics.ExcludeClip(ExcludeRegion6);
point1.X=480;point1.Y=250;
point2.X=469;point2.Y=264;
point3.X=446;point3.Y=278;
Point[] curvePoints6 = { point1, point2, point3 };
GraphicsPath myPath4 = new GraphicsPath();
myPath4.AddCurve(curvePoints6, 0, 2, 0.8f);
myPath4.AddLine(450, 277, 495, 279);
Region ExcludeRegion5 = new Region(myPath4);
e.Graphics.ExcludeClip(ExcludeRegion5);
e.Graphics.DrawImage(img, 0, 0, 495,278);
// Reset clipping region to infinite.
e.Graphics.ResetClip();
}
private void button1_Click(object sender, System.EventArgs e){
Application.Exit();
}
private void Playing_MouseEnter(object sender, System.EventArgs e){ this.Playing.Image = System.Drawing.Bitmap.FromFile("PlayingOver.jpg");
disp.Text = "Play Mode";
}
private void Circle_MouseEnter(object sender, System.EventArgs e){ this.Circle.Image = System.Drawing.Bitmap.FromFile("CircleOver.jpg");
if(playFlg)
disp.Text = "Play ...";
else
disp.Text = "Start Play";
}
private void Circle_MouseLeave(object sender, System.EventArgs e) {
this.Circle.Image = System.Drawing.Bitmap.FromFile("Circle.jpg");
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
private void pictureBox1_Click(object sender, System.EventArgs e){ this.Playing.Image = System.Drawing.Bitmap.FromFile("PlayingUp.jpg"); }
private void Playing_Click(object sender, System.EventArgs e){ this.CDAudio.Image = System.Drawing.Bitmap.FromFile("CDAudio.jpg"); }
private void CDAudio_MouseEnter(object sender, System.EventArgs e){ this.CDAudio.Image = System.Drawing.Bitmap.FromFile("CDOver.jpg");
disp.Text = "Select CD";
}
private void CDAudio_MouseLeave(object sender, System.EventArgs e){ this.CDAudio.Image = System.Drawing.Bitmap.FromFile("CDAudio.jpg");
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
private void Playing_MouseLeave(object sender, System.EventArgs e){ this.Playing.Image = System.Drawing.Bitmap.FromFile("PlayingUp.jpg");
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
private void button1_Click_1(object sender, System.EventArgs e){
Application.Exit();
}
private void smBut_Click(object sender, System.EventArgs e){
Invalidate();
}
private void smBut_MouseEnter(object sender, System.EventArgs e){ smBut.Image = System.Drawing.Bitmap.FromFile("buttonOver2.jpg");
disp.Text = "Hi .... from Jibin Pan";
}
private void smBut_MouseLeave(object sender, System.EventArgs e) { smBut.Image = System.Drawing.Bitmap.FromFile("buttonNormal.jpg");
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
private void stopBut_MouseEnter(object sender, System.EventArgs e){ stopBut.Image = System.Drawing.Bitmap.FromFile("stopButOver.jpg");
disp.Text = "Stop Play";
}
private void stopBut_MouseLeave(object sender, System.EventArgs e){ stopBut.Image = System.Drawing.Bitmap.FromFile("stopButNormal.jpg");
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
public void Form1_MouseMove(object sender, MouseEventArgs e){ if( blnMoving ){
Point temp = new Point(0,0);
temp.X = this.Location.X + (e.X - MouseDownX);
temp.Y = this.Location.Y + (e.Y - MouseDownY);
this.Location = temp;
}
}
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e){ if (e.Button == MouseButtons.Left){
blnMoving = true;
MouseDownX = e.X;
MouseDownY = e.Y;
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){ if (e.Button == MouseButtons.Left)
blnMoving = false;
}
private void Ex_MouseEnter(object sender, System.EventArgs e) {
disp.Text = "Exit";
}
private void Ex_MouseLeave(object sender, System.EventArgs e){
disp.Text = "";
if(playFlg)
disp.Text = "Play ...";
}
private void Circle_Click(object sender, System.EventArgs e){
disp.Text = "Play ...";
playFlg = true;
for ( int i = 1; i < 9; i++ )
imgList.Add( Image.FromFile( "hotc" + i + ".jpg" ) );
if(imgList.Count > 1)
animatPicture.Image = (Image) imgList[ 0 ];
}
private void time1_Tick(object sender, EventArgs e){
DateTime t = DateTime.Now;
tm.Text = t.ToLongTimeString();
cnt = ( cnt + 1 ) % 15;
if(imgList.Count > 1 && imgList.Count > cnt)
animatPicture.Image = ( Image )imgList[ cnt ];
}
private void stopBut_Click(object sender, System.EventArgs e){ playFlg = false;
imgList.Clear();
}
}
}。

相关文档
最新文档