请教一个重绘操作的做法,以zedGraph为背景做GDI画图,重绘事件怎么处理
时间:2011-12-13
来源:互联网
具体代码如下,已经实现图形平移,但是图形被覆盖时,重绘事件做不出来,有知道的吗,敬请指教
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace GDIPlot
{
public partial class Form1 : Form
{
GraphPane picBackground;
Graphics testLine;
Pen linePen = new Pen(Color.White);
int count = 0;
int picWidth;
int picHeight;
System.Random rd = new Random();
int picOriginX;
int picOriginY;
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwrop);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
picBackground = zedGraphControl1.GraphPane;
picBackground.XAxis.Type = AxisType.DateAsOrdinal;
testLine = zedGraphControl1.CreateGraphics();
Pen linePen;
this.DoubleBuffered = true;
}
private void Form1_Resize(object sender, EventArgs e)
{
picBackground = zedGraphControl1.GraphPane;
textBox1.Text = picBackground.Chart.Rect.X.ToString();
textBox2.Text = picBackground.Chart.Rect.Y.ToString();
textBox3.Text = picBackground.Chart.Rect.Width.ToString();
textBox4.Text = picBackground.Chart.Rect.Height.ToString();
}
private void zedGraphControl1_MouseDoubleClick(object sender, MouseEventArgs e)
{
textBox5.Text = e.X.ToString();
textBox6.Text = e.Y.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
textBox1.Text = picBackground.Chart.Rect.X.ToString();
textBox2.Text = picBackground.Chart.Rect.Y.ToString();
textBox3.Text = picBackground.Chart.Rect.Width.ToString();
textBox4.Text = picBackground.Chart.Rect.Height.ToString();
picHeight = (int)(picBackground.Chart.Rect.Height)-4;
picWidth = (int)(picBackground.Chart.Rect.Width)-4;
picOriginX = (int)picBackground.Chart.Rect.X+4;
picOriginY = (int)picBackground.Chart.Rect.Y+3;
}
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr ihandle = testLine.GetHdc();
BitBlt(ihandle, picOriginX + 1, picOriginY, picWidth - 1, picHeight, ihandle, picOriginX, picOriginY, 13369376);
testLine.ReleaseHdc(ihandle);
for (int i = 0; i < picHeight; i++)
{
int rand1 = (int)(rd.NextDouble() * 255);
linePen.Color = Color.FromArgb(rand1, 0,255);
linePen.Width = 1.0F;
testLine.DrawLine(linePen, picOriginX, i + picOriginY, picOriginX, i + 1 + picOriginY);
}
textBox7.Text = count.ToString();
count++;
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}
private void zedGraphControl1_Paint(object sender, PaintEventArgs e)
{
//重绘
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace GDIPlot
{
public partial class Form1 : Form
{
GraphPane picBackground;
Graphics testLine;
Pen linePen = new Pen(Color.White);
int count = 0;
int picWidth;
int picHeight;
System.Random rd = new Random();
int picOriginX;
int picOriginY;
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwrop);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
picBackground = zedGraphControl1.GraphPane;
picBackground.XAxis.Type = AxisType.DateAsOrdinal;
testLine = zedGraphControl1.CreateGraphics();
Pen linePen;
this.DoubleBuffered = true;
}
private void Form1_Resize(object sender, EventArgs e)
{
picBackground = zedGraphControl1.GraphPane;
textBox1.Text = picBackground.Chart.Rect.X.ToString();
textBox2.Text = picBackground.Chart.Rect.Y.ToString();
textBox3.Text = picBackground.Chart.Rect.Width.ToString();
textBox4.Text = picBackground.Chart.Rect.Height.ToString();
}
private void zedGraphControl1_MouseDoubleClick(object sender, MouseEventArgs e)
{
textBox5.Text = e.X.ToString();
textBox6.Text = e.Y.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
textBox1.Text = picBackground.Chart.Rect.X.ToString();
textBox2.Text = picBackground.Chart.Rect.Y.ToString();
textBox3.Text = picBackground.Chart.Rect.Width.ToString();
textBox4.Text = picBackground.Chart.Rect.Height.ToString();
picHeight = (int)(picBackground.Chart.Rect.Height)-4;
picWidth = (int)(picBackground.Chart.Rect.Width)-4;
picOriginX = (int)picBackground.Chart.Rect.X+4;
picOriginY = (int)picBackground.Chart.Rect.Y+3;
}
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr ihandle = testLine.GetHdc();
BitBlt(ihandle, picOriginX + 1, picOriginY, picWidth - 1, picHeight, ihandle, picOriginX, picOriginY, 13369376);
testLine.ReleaseHdc(ihandle);
for (int i = 0; i < picHeight; i++)
{
int rand1 = (int)(rd.NextDouble() * 255);
linePen.Color = Color.FromArgb(rand1, 0,255);
linePen.Width = 1.0F;
testLine.DrawLine(linePen, picOriginX, i + picOriginY, picOriginX, i + 1 + picOriginY);
}
textBox7.Text = count.ToString();
count++;
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}
private void zedGraphControl1_Paint(object sender, PaintEventArgs e)
{
//重绘
}
}
}
作者: swj03393 发布时间: 2011-12-13
this.zedGraphControl.AxisChange();
this.zedGraphControl.Refresh();
作者: Netteans 发布时间: 2011-12-14
厄,这个不行啊,这个只是刷新zedgraph控件的坐标啊。我想重绘teseline画的图啊
作者: swj03393 发布时间: 2011-12-14
谁能告诉我啊,我都愁死了。。。
作者: swj03393 发布时间: 2011-12-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28