C# 绘图求救

eiwang 2010-09-08 05:53:06
绘图总是一个数组传递给Graphics,然后根据定义的颜色和Pen来绘制。
但是实际当中会有很多很多数据,比如每三秒中就有数据增加。那这个图该怎么绘制呢?那这个数组不是海了去了?
请大家给支招,谢谢~~
...全文
167 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
TNight 2010-09-08
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Drawing
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
TNight 2010-09-08
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Drawing
{
/// <summary>
/// 直线对象
/// </summary>
class Line
{
private int x1;
private int y1;
private int x2;
private int y2;

// 线条宽度
private int strokeWidth;

public int StrokeWidth
{
get { return strokeWidth; }
set { strokeWidth = value; }
}

// 线条颜色
private Color strokeColor;

public Color StrokeColor
{
get { return strokeColor; }
set { strokeColor = value; }
}

public Line()
{
StrokeWidth = 1;
StrokeColor = Color.Black;
}

public void Draw(Graphics graphics)
{
graphics.DrawLine(new Pen(StrokeColor, StrokeWidth), x1, y1, x2, y2);
}

public void SetPoint1(Point point)
{
x1 = point.X;
y1 = point.Y;
}

public void SetPoint2(Point point)
{
x2 = point.X;
y2 = point.Y;
}
}
}
这是line.cs,上面那个是form.cs
TNight 2010-09-08
  • 打赏
  • 举报
回复
你是要简单的绘图程序?呵呵我这这几天正好做这个
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Drawing
{
public partial class Form1 : Form
{
string BoolStyle;
Line lineObj;
Circle circleObj;
Rectangle rectangleObj;
RectCircle rectcircleOjt;
Color[] DrawColor;
Color currentcolor;
bool c;
List<Line> listline = new List<Line>();
List<Circle> listcircle = new List<Circle>();
List<Rectangle> listrectangle = new List<Rectangle>();
List<RectCircle> listrectcircle = new List<RectCircle>();
public Form1()
{
currentcolor = Color.Black;
DrawColor = new Color[8];
DrawColor[0] = Color.Brown;
DrawColor[1] = Color.Red;
DrawColor[2] = Color.Blue;
DrawColor[3] = Color.Orange;
DrawColor[4] = Color.Green;
DrawColor[5] = Color.Yellow;
DrawColor[6] = Color.White;
DrawColor[7] = Color.Black;
InitializeComponent();
}

private void Btn1_Click(object sender, EventArgs e)
{
BoolStyle = "line";
}

private void Btn2_Click(object sender, EventArgs e)
{
BoolStyle = "circle";
}

private void Btn3_Click(object sender, EventArgs e)
{
BoolStyle = "rectangle";
}
private void Btn4_Click(object sender, EventArgs e)
{
BoolStyle = "rectcircle";
}

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
c = true;
switch (BoolStyle)
{
case "line":
lineObj = new Line();
lineObj.SetPoint1(e.Location);
listline.Add(lineObj);
lineObj.StrokeColor = currentcolor;
break;
case "circle":
circleObj = new Circle();
circleObj.SetCenterPoint(e.Location);
listcircle.Add(circleObj);
circleObj.StrokeColor = currentcolor;
break;
case "rectangle":
rectangleObj = new Rectangle();
rectangleObj.SetLeftTop(e.Location);
listrectangle.Add(rectangleObj);
rectangleObj.StrokeColor = currentcolor;
break;
case "rectcircle":
rectcircleOjt = new RectCircle();
listrectcircle.Add(rectcircleOjt);
rectcircleOjt.SetLeftTop(e.Location);
rectcircleOjt.StrokeColor = currentcolor;
break;
default:
break;

}
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (c == true)
{
switch (BoolStyle)
{
case "line":
lineObj.SetPoint2(e.Location);
break;
case "circle":
circleObj.SetRadius(e.Location);
break;
case "rectangle":
rectangleObj.SetRightBottom(e.Location);
break;
case "rectcircle":
rectcircleOjt.SetRightBottom(e.Location);
break;
default:
break;

}
}
panel1.Refresh();
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
c = false;

switch (BoolStyle)
{
case "line":

lineObj = null;
break;
case "circle":
circleObj = null;
break;
case "rectangle":
rectangleObj = null;
break;
case"rectcircle":
rectcircleOjt = null;
break;
default:
break;

}

}

private void panel1_Paint(object sender, PaintEventArgs e)
{
/* if (x)
{
switch (BoolStyle)
{
case "line":
lineObj.Draw(e.Graphics);
break;
case "circle":
circleObj.Draw(e.Graphics);
break;
case "rectangle":
rectangleObj.Draw(e.Graphics);
break;
default :
break;

}
}*/
Graphics g = e.Graphics;
for (int i=0;i<listline.Count;i++)
listline[i].Draw(g);

foreach(Circle circle in listcircle)
{
circle.Draw(e.Graphics);
}
foreach(Rectangle rectangle in listrectangle)
{
rectangle.Draw(e.Graphics);
}
foreach (RectCircle rectcircle in listrectcircle)
{
rectcircle.Draw(e.Graphics);
}
}

private void panel2_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(currentcolor), 20, 0, 30, 20);
g.DrawRectangle(new Pen(Color.Black), 20, 0, 30, 20);
int x=80;
for (int i=0;i<DrawColor.Length;i++)
{
g.FillRectangle(new SolidBrush(DrawColor[i]), x, 0, 30, 20);
g.DrawRectangle(new Pen(Color.Black), 20, 0, 30, 20);
x += 30;
}

}

/* private void panel2_Click(object sender, EventArgs e)
{
int x = e.X;
int y = e.Y;
if (x>80&&y<30)
{
int colorindex = (x - 80) / 30;
if (colorindex < DrawColor.Length)
{
currentcolor = DrawColor[colorindex];
}
}
panel2.Refresh();
}*/

private void panel2_MouseClick(object sender, MouseEventArgs e)
{
int x = e.X;
int y = e.Y;
if (x > 80 && y < 30)
{
int colorindex = (x - 80) / 30;
if (colorindex < DrawColor.Length)
{
currentcolor = DrawColor[colorindex];
}
}
panel2.Refresh();
}



}

}
jointan 2010-09-08
  • 打赏
  • 举报
回复
如果不是绘制分时图的话,在同一个BitMap上反复画.在接到数据时画,不要在Paint事件中画,在Paint事件中,把图"贴"到Graphics中就可以了
ckl881003 2010-09-08
  • 打赏
  • 举报
回复
你绘的图能显示出多少数据那是关键吧。。
zhui22222 2010-09-08
  • 打赏
  • 举报
回复
一次只绘制一部分,利用鼠标拖动事件绘制其他部分,或者利用鼠标滚轮实现放大缩小等功能
gaara777 2010-09-08
  • 打赏
  • 举报
回复
用循环3秒钟收集下,,再把数据储存起来啊。.那么多线很难区分出来的,.
eiwang 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 libinguest 的回复:]

5万个进行绘制算多吗?

http://download.csdn.net/source/1531255
[/Quote]

每3秒一条数据,三年的数据是多少条?所以得有个好的解决方案才是。谢谢你,如果有设计方案解决就好了,比如使用绘制图形的拼接绘制等实例 的话就好了
风之影子 2010-09-08
  • 打赏
  • 举报
回复
5万个进行绘制算多吗?

http://download.csdn.net/source/1531255
eiwang 2010-09-08
  • 打赏
  • 举报
回复
自己顶一个~~ 有知道的朋友给个建议 谢谢

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧