C# 绘图求救

eiwang 2010-09-08 05:53:06
绘图总是一个数组传递给Graphics,然后根据定义的颜色和Pen来绘制。
但是实际当中会有很多很多数据,比如每三秒中就有数据增加。那这个图该怎么绘制呢?那这个数组不是海了去了?
请大家给支招,谢谢~~
...全文
165 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
  • 打赏
  • 举报
回复
自己顶一个~~ 有知道的朋友给个建议 谢谢
下载代码方式:https://pan.quark.cn/s/dd3561eca308 在软件开发领域,面向对象编程(OOP)是一种普遍采纳的结构化方法,它使得开发者能够借助模拟现实环境中的实体和关系来构建软件系统。在本案例中,我们观察到的是一个关于借助抽象类来执行不同几何图形面积求解的实践应用。现在,让我们详细分析这一议题。 标题 "应用抽象类计算面积" 清晰地表明我们将要讨论一个抽象类,此类设定了一个用于测量图形面积的标准函数,但并未提供实际的执行过程。抽象类在诸如C#或Java等编程语言中通常借助`abstract`修饰符进行声明,它们无法直接创建对象实例,仅能作为其他类的基础模板。 描述部分提及的"图形界面应用"暗示这是一个基于视觉用户界面(GUI)的系统,可能运用了.NET Framework的Windows Forms或WPF技术,或者是Java平台的Swing或JavaFX框架。在这样环境下,用户能够通过视觉元素与这些几何体进行互动,例如输入相关尺寸并观看到计算得出的面积值。 抽象类“几何体”内嵌了“计算面积”这一抽象函数。在代码层面,这可以被表述为: ```csharp public abstract class GeometricShape { public abstract double CalculateArea(); } ``` 随后,有三个派生类:圆(Circle)、矩形(Rectangle)和三角形(Triangle),它们各自提供了这个抽象函数的具体实现。比如,圆的面积是通过π乘以半径的平方得到的,矩形的面积是长和宽的乘积,而三角形的面积可能是底乘以高再除以2的结果。这些类将提供具体实现来计算它们各自的面积: ```csharp p...
内容概要:本文系统研究了移相控制全桥LLC谐振变换器的工作特性,深入分析其在不同工作模式下的运行机理与性能表现,重点探讨了软开关实现、高效率能量转换及宽范围电压调节等关键技术优势。通过Simulink搭建精确的仿真模型,对谐振腔参数、开关频率、电压增益、系统效率等关键指标进行仿真分析,验证了理论设计的正确性。同时,详细研究了移相控制策略对系统动态响应、稳定性和轻载/重载工况适应性的影响,揭示了控制参数与电路参数之间的耦合关系,为高频高效电源设计提供了理论依据和实践指导。; 适合人群:具备电力电子技术、模拟电路及自动控制理论基础,从事开关电源、新能源变换器、电动汽车充电模块或高频电源系统研发的工程师及高校研究生。; 使用场景及目标:①掌握全桥LLC谐振变换器的拓扑结构、工作原理与关键参数设计方法;②理解移相控制在实现零电压开通(ZVS)和零电流关断(ZCS)中的作用机制;③通过Simulink仿真掌握变换器建模、参数优化与性能评估流程,服务于实际产品开发与学术课题研究。; 阅读建议:建议读者结合提供的Simulink仿真模型进行同步操作,重点关注谐振网络(Lr, Lm, Cr)参数与移相角之间的匹配设计,深入理解软开关条件的形成过程,并通过调整负载和输入电压进行多工况仿真,以全面掌握系统动态特性。

111,129

社区成员

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

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

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