C# 具有背景栅格的绘曲线类(一)(转帖)
2012-07-05 10:11
686 查看
原文转自:/article/11436471.html
本文实现了用于绘制曲线的通用类,类实现对背景栅格的绘制,并将由外部传入到先进先出栈中的数据作为
本文实现了用于绘制曲线的通用类,类实现对背景栅格的绘制,并将由外部传入到先进先出栈中的数据作为
[csharp] view plaincopyprint? 曲线的关键点,返回一个位图的对象用于显示曲线。 曲线的关键点,返回一个位图的对象用于显示曲线。
using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.Drawing; namespace PID_Control { class Curve { public Queue KeyDots=new Queue(); //曲线关键点 private Graphics objGraphic;//提供绘制的方法 public Bitmap objBitmap;//位图对象 private Point CurrentPoint = new Point(0, 0); //当前点 private Point LastPoint = new Point(50, 635); //最后的点 private int m_Width = 900;// 图像宽度 private int m_Height = 650;//图像高度 private int m_XGrid = 50;//栅格X长度 private int m_YGrid = 50;//栅格Y长度 private Color m_BorderColor = Color.Blue; //边框颜色 private Color m_BgColor = Color.Black;//背景颜色 private Color m_GridColor = Color.Gray;//栅格颜色 public int Width { set { m_Width =value; } get { return m_Width; } } public int Height { set { m_Height = value; } get { return m_Height; } } public Color BorderColor { set { m_BorderColor = value; } get { return m_BorderColor; } } public Color BgColor { set { m_BgColor = value; } get { return m_BgColor; } } public Color GridColor { set { m_GridColor = value; } get { return m_GridColor; } } public int XGrid { set { m_XGrid = value; } get { return m_XGrid; } } public int YGrid { set { m_YGrid = value; } get { return m_YGrid; } } public Curve() { InitializeGraph(); DrawContent(); } public void InitializeGraph() { //创建指定高度和宽度的位图对象 objBitmap = new Bitmap(Width, Height); //从位图对象中创建Graphics对象 objGraphic = Graphics.FromImage(objBitmap); //创建指定颜色的矩形边框 objGraphic.DrawRectangle(new Pen(BorderColor, 1),0,0, Width, Height); objGraphic.FillRectangle(new SolidBrush(BgColor),1,1, Width, Height); //画X方向栅格并标注 int t = 0; for (int i = Height-15; i >= 0; i -= YGrid) { objGraphic.DrawLine(new Pen(GridColor, 1), 50, i, Width, i); objGraphic.DrawString(System.Convert.ToString(t*5000), new Font("宋体", 10), new SolidBrush(Color.White), 0, i); t++; } //画Y方向栅格并标注 t = 0; for (int i = 50; i < Width; i += XGrid) { objGraphic.DrawLine(new Pen(GridColor, 1), i, 0, i, Height-15); objGraphic.DrawString(System.Convert.ToString(t), new Font("宋体", 10), new SolidBrush(Color.White), i, Height-13); t++; } } public void DrawContent() { while (KeyDots.Count > 0) { //设置新点坐标 CurrentPoint.X = LastPoint.X + 2; CurrentPoint.Y = Height-System.Convert.ToInt16(KeyDots.Dequeue())-15; objGraphic.DrawLine(new Pen(Color.Red, 2),LastPoint,CurrentPoint); //重置最后点坐标 LastPoint = CurrentPoint; if (LastPoint.X > Width) { InitializeGraph(); LastPoint.X = 50; } } } } }
相关文章推荐
- C# 具有背景栅格的绘曲线类(一)
- C#发现之旅 --- WinForm.NET中开发具有固定背景图片的可滚动控件
- 串口绘制曲线(基于C#绘制曲线类)(转帖)
- C#发现之旅: WinForm.NET中开发具有固定背景图片的可滚动控件
- C#发现之旅 --- WinForm.NET中开发具有固定背景图片的可滚动控件
- C#发现之旅 --- WinForm.NET中开发具有固定背景图片的可滚动控件
- C#发现之旅 --- WinForm.NET中开发具有固定背景图片的可滚动控件
- C#发现之旅 --- WinForm.NET中开发具有固定背景图片的可滚动控件
- JavaScript调用C#办法-转帖
- C#:如何设置桌面背景
- asp.net+C# 开发网页区域更新的方法 .(转帖)
- 求任意曲线的长度(C#)
- c#.net画曲线图(坐标)
- C#验证码,彩色背景的啊。
- 用ASP.NET with C# 绘制曲线图(Curve图)转
- C# +AE加载shp、栅格、地图文档数据
- C# 报错:键字“Parent”之后应当是具有可能的关系限定符的单个列参数: Parent)].。
- Java_GUI中实现paintComponent方法并画背景图片和曲线的方法
- C#Winform中运用DevExpress提供的ChartControl控件绘制多条曲线图
- C#将图片白色背景设置为透明