+ -
当前位置:首页 → 问答吧 → 请教一个重绘操作的做法,以zedGraph为背景做GDI画图,重绘事件怎么处理

请教一个重绘操作的做法,以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)
  {
  //重绘
  }

  }
}


作者: swj03393   发布时间: 2011-12-13


  this.zedGraphControl.AxisChange();
  this.zedGraphControl.Refresh();

作者: Netteans   发布时间: 2011-12-14

厄,这个不行啊,这个只是刷新zedgraph控件的坐标啊。我想重绘teseline画的图啊

作者: swj03393   发布时间: 2011-12-14

谁能告诉我啊,我都愁死了。。。

作者: swj03393   发布时间: 2011-12-14