资源简介
这个程序是用C#编写的,用GDI+绘制一个动态的二维平面坐标,用户能通过输入X轴和Y轴的最小刻度来控制平面坐标的大小,并通过产生一个随机数波形,来动态显示平面坐标。
希望这个小程序能对学习使用C#GDI+绘图的朋友带来帮助。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace DrawPlane
{
class Draw
{
public Bitmap mybitmap;//用于双缓冲的位图,和画布等大
Random rm = new Random();
public void DrawLineS(Color color float Xmark float Ymark PictureBox picboxPoint[] ptlist)
{
mybitmap = new Bitmap(picbox.Width picbox.Height);//设定位图大小
Graphics doublebufferg = Graphics.FromImage(mybitmap);//从位图上获取画布
doublebufferg.Clear(Color.White);//用背景色刷新
//pictureBox1填充为白色,便于显示图像 500*300
Rectangle rect = new Rectangle(0 0 picbox.Width picbox.Height);
doublebufferg.FillRectangle(new SolidBrush(Color.White) rect);
//画X轴和Y轴
DrawXY(ref doublebufferg picbox);
//X轴上的刻度
SetXAxis(ref doublebufferg picbox Xmark);
//Y轴上的刻度
SetYAxis(ref doublebufferg picbox Ymark);
//绘制实时随机曲线
Point temp = new Point();
for (int j = 0; j < picbox.Width / 5-1; j++)
{
temp = ptlist[j + 1];
ptlist[j] = new Point(temp.X - 5 temp.Y);
}
Point lastpt = new Point();
lastpt.X = picbox.Width;
lastpt.Y = rm.Next(DateTime.Now.Millisecond) % picbox.Height;
ptlist[picbox.Width / 5 -1] = lastpt;
doublebufferg.DrawLines(new Pen(Color.Red2) ptlist);
//将缓冲中的位图绘制到窗体上
Graphics g1 = picbox.CreateGraphics();//创建 PictureBox窗体的画布
g1.Clear(Color.White);
g1.DrawImage(mybitmap 0 0);
}
//画X轴和Y轴的基本部分,包括间隔、方向箭头
public void DrawXY(ref Graphics g PictureBox picbox)
{
Pen pen = new Pen(Color.Green 2);//画笔
SolidBrush sb = new SolidBrush(Color.Green);//画刷
//X轴上的方向箭头,实际上是绘制了一个三角形
Point[] xpts = new Point[3]{
new Point(picbox.Width-35picbox.Height-32)
new Point(picbox.Width-35picbox.Height-28)
new Point(picbox.Width-30picbox.Height-30)
};
g.DrawLine(pen 30 picbox.Height - 30 picbox.Width - 30 picbox.Height - 30);//绘制X坐标轴
g.DrawPolygon(penxpts);//绘制X轴的方向箭头
g.DrawString(“X轴“ new Font(“宋体“ 9) sb picbox.Width - 25 picbox.Height - 35);//标注X轴
//Y轴的箭头,实际上是绘制了一个三角形
Point[] ypts = new Point[3]{
new Point(2835)
new Point(3030)
new Point(3235) };
g.DrawLine(pen 30 picbox.Height - 30 30 30);
g.DrawPolygon(pen ypts);
g.DrawString(“Y轴“ new Font(“宋体“ 9) sb 20 10);
}
//绘制平行Y轴的竖线,相当于X轴上的刻度
public void SetXAxis(ref Graphics g PictureBox picbox
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12800 2011-03-27 11:37 DrawPlane\DrawPlane\bin\Debug\DrawPlane.exe
文件 30208 2011-03-27 11:37 DrawPlane\DrawPlane\bin\Debug\DrawPlane.pdb
文件 14328 2011-03-27 11:45 DrawPlane\DrawPlane\bin\Debug\DrawPlane.vshost.exe
文件 490 2007-07-21 01:33 DrawPlane\DrawPlane\bin\Debug\DrawPlane.vshost.exe.manifest
文件 5521 2011-03-27 11:37 DrawPlane\DrawPlane\Draw.cs
文件 3764 2011-03-23 10:22 DrawPlane\DrawPlane\DrawPlane.csproj
文件 3020 2011-03-27 11:22 DrawPlane\DrawPlane\Form1.cs
文件 5867 2011-03-27 11:06 DrawPlane\DrawPlane\Form1.Designer.cs
文件 6008 2011-03-27 11:06 DrawPlane\DrawPlane\Form1.resx
文件 618 2011-03-27 11:45 DrawPlane\DrawPlane\obj\Debug\DrawPlane.csproj.FileListAbsolute.txt
文件 847 2011-03-27 11:06 DrawPlane\DrawPlane\obj\Debug\DrawPlane.csproj.GenerateResource.Cache
文件 12800 2011-03-27 11:37 DrawPlane\DrawPlane\obj\Debug\DrawPlane.exe
文件 180 2011-03-27 11:06 DrawPlane\DrawPlane\obj\Debug\DrawPlane.Form1.resources
文件 30208 2011-03-27 11:37 DrawPlane\DrawPlane\obj\Debug\DrawPlane.pdb
文件 180 2011-03-23 10:22 DrawPlane\DrawPlane\obj\Debug\DrawPlane.Properties.Resources.resources
文件 490 2011-03-23 09:42 DrawPlane\DrawPlane\Program.cs
文件 1374 2011-03-23 09:42 DrawPlane\DrawPlane\Properties\AssemblyInfo.cs
文件 2868 2011-03-23 09:42 DrawPlane\DrawPlane\Properties\Resources.Designer.cs
文件 5612 2011-03-23 09:42 DrawPlane\DrawPlane\Properties\Resources.resx
文件 1094 2011-03-23 09:42 DrawPlane\DrawPlane\Properties\Settings.Designer.cs
文件 249 2011-03-23 09:42 DrawPlane\DrawPlane\Properties\Settings.settings
文件 917 2011-03-23 09:42 DrawPlane\DrawPlane.sln
..A..H. 15872 2011-03-27 12:03 DrawPlane\DrawPlane.suo
目录 0 2011-03-23 12:33 DrawPlane\DrawPlane\obj\Debug\Refactor
目录 0 2011-03-23 09:42 DrawPlane\DrawPlane\obj\Debug\TempPE
目录 0 2011-03-23 10:22 DrawPlane\DrawPlane\bin\Debug
目录 0 2011-03-27 11:37 DrawPlane\DrawPlane\obj\Debug
目录 0 2011-03-23 09:42 DrawPlane\DrawPlane\bin
目录 0 2011-03-23 09:42 DrawPlane\DrawPlane\obj
目录 0 2011-03-23 09:42 DrawPlane\DrawPlane\Properties
............此处省略5个文件信息
- 上一篇:获取鼠标所在窗口的句柄、类名c#
- 下一篇:C#和西门子PLC1200 以太网通讯
相关资源
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
评论
共有 条评论