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

Reading number is top 10 articles
XML入门教程-现实生活中的XML_[XML教程]
浅谈,DotNet,保护中字符串加密的技术_.net资料_编程技术
sqlserver过滤字符串中的空格的自定义函数_[SQL,Server教程]
PHP的strtok()函数实例应用_[PHP教程]
javascript特效:将HTML自动转为JS代码_JavaScript技术_编程技术
在.NET下多层架构企业管理系统的开发_[Asp.Net教程]
ASP.NET编程精选25种函数源程序_[Asp.Net教程]
ASP.NET,2005,Treeview终极解决方案_[Asp.Net教程]
C#,中返回上一页问题代码_[Asp.Net教程]
GridView中实现并列排名的例子_[Asp.Net教程]
Reading number is top 10 pictures
29 the belle stars after bath figure5
清纯性感的美眉1
六种更聪明的工作方法
The money of more than 100 countries and regions3
红楼梦金陵十二钗(1)
The money of more than 100 countries and regions14
Household design classic black and white
Photographed the passion of the clients and prostitutes in the sex trade picture2
Chinese paper-cut grilles art appreciation1
治疗多发性骨髓瘤的特效药,一万二一支
Download software ranking
The Bermuda triangle3
Boxer's Top ten classic battle10
Unix video tutorial8
Professional killers2 data package
Unix video tutorial19
jdk1.6 for windows
Unix video tutorial17
C#高级编程(第4版)
The Bermuda triangle1
Popkart Cracked versions Mobile phone games
qq published in(发表于) 2014/7/11 9:16:48 Edit(编辑)
c#中GDI+图形图像:GDI+中的直线和矩形使用方法

c#中GDI+图形图像:GDI+中的直线和矩形使用方法

c#中GDI+图形图像:GDI+中的直线和矩形使用方法

GDI+中的直线和矩形

1.绘制直线

绘制直线时,可以调用Graphics类中的DrawLine方法,该方法为可重载方法,它主要用来绘制一条连接由坐标对指定的两个点的线条,其常用格式有以下两种。

(1)绘制一条连接两个Point结构的线。

语法:

public void DrawLine (

Pen pen,

Point pt1,

Point pt2)

参数说明如下。

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

pt1:Point结构,它表示要连接的第一个点。

pt2:Point结构,它表示要连接的第二个点。

(2)绘制一条连接由坐标对指定的两个点的线条。

语法:

public void DrawLine (

Pen pen,

int x1,

int y1,

int x2,

int y2)

DrawLine方法中各参数及说明如表1所示。



表1 DrawLine方法参数及说明

示例

绘制直线

本示例实现的是,当程序运行时,单击【绘制直线】按钮,在窗体中的指定位置绘制一条直线。示例运行结果如图1所示。



图1 绘制直线

程序代码如下。

Form1窗体中,在【绘制直线】按钮的Click事件中分别声明Graphics类和Pen类的两个实例对象,然后调用Graphics对象的DrawLine方法在窗体中绘制一条直线。【绘制直线】按钮的Click事件代码如下网站源代码

private void button1_Click(object sender, EventArgs e)

{//本教程来自:HTTP://www.isstudy.com

Graphics graphics = this.CreateGraphics();

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

graphics.DrawLine(myPen, 50, 30, 170, 30);

}

完整程序代码如下:

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

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _6_01

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

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

graphics.DrawLine(myPen, 50, 30, 170, 30);

}

}

}

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

namespace _6_01

{

partial class Form1

{

///



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

///


private System.ComponentModel.IContainer components = null;

///

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

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//本教程来自:HTTP://www.isstudy.com

// button1

//

this.button1.Location = new System.Drawing.Point(63, 61);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 0;

this.button1.Text = "绘制直线";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(212, 106);

this.Controls.Add(this.button1);

this.MaximizeBox = false;

this.Name = "Form1";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button1;

}

}

★ ★★★★Program.cs主程序文件完整程序代码网站源代码★★★★★

using System;


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