C# 怎么画这图?多谢 =

cy_zh 2011-01-12 12:23:12
师傅让我做个图
从3000到5000之间取出 200个随机数,每秒20个,然后实时显示,,各位高人们这个怎么做啊?
...全文
182 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
luguo3000 2011-01-12
  • 打赏
  • 举报
回复
答案都挺好的
gomoku 2011-01-12
  • 打赏
  • 举报
回复

public partial class Form1 : Form
{
Timer timer = new Timer();
Random random = new Random();
List<PointF> points = new List<PointF>();

public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
timer.Interval = 1000 / 20;
timer.Tick += delegate { this.Invalidate(); };
timer.Start();
}

protected override void OnPaint(PaintEventArgs e)
{
const int SampleCount = 200, Min = 3000, Max = 5000;
if (points.Count < SampleCount)
{
this.points.Add(new PointF(
this.Width / (SampleCount + 1.0f) * (1 + points.Count),
this.Height / (Max - Min + 1.0f) * (random.Next(Min, Max) - Min)
));
}
if (points.Count > 1)
{
e.Graphics.DrawLines(Pens.Blue, points.ToArray());
}
}
}
bdmh 2011-01-12
  • 打赏
  • 举报
回复

int[] arr = new int[20];

private void timer1_Tick(object sender, EventArgs e)
{
Random rand = new Random();
for (int i = 0; i < 20; i++)
{
arr[i] = rand.Next(3000, 5000);
}
this.Invalidate();

}

private void DrawItems(int[] arr,Graphics g)
{
for (int i = 0; i < arr.Length; i++)
{
g.DrawString(arr[i].ToString(), this.Font, new SolidBrush(Color.Red), 0, 20 * i);
}
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawItems(arr, e.Graphics);

}
lizhibin11 2011-01-12
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/ms771684(v=vs.90).aspx
cy_zh 2011-01-12
  • 打赏
  • 举报
回复
具体怎么去实现啊?我刚接触C#,不知道从哪儿下手,谁有个什么小例子啥的不?谢谢啊,我邮箱cy_zhao@sina.cn
lizhibin11 2011-01-12
  • 打赏
  • 举报
回复
有三种方式
第一种、使用GDI+的graphic类;
第二种、使用WPF的drawingvisual类;
第三种、使用托管directx的device类。
具体使用方法你可以看这些类的成员。
wangsong145 2011-01-12
  • 打赏
  • 举报
回复
用timer控件和Random函数
cy_zh 2011-01-12
  • 打赏
  • 举报
回复
谢谢大家
那我在picturebox里显示那些怎么是一点一点的啊,用鼠标点一下那个窗口就出点,这是为什么呢?

110,533

社区成员

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

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

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