我用GDI+在pictureBox 的 onpaint事件中画了折线图,现在想实现鼠标在坐标系中移动时显示当前坐标的值 要求显示的字体位置随着鼠标移动 请问怎样实现 最好不用其它控件直接在图上画出来。。 非常感谢

解决方案 »

  1.   

    private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
           pictureBox1.Image = (Bitmap)bitmap.Clone();
           Graphics g = Graphics.FromImage(pictureBox1.Image);
            g.DrawLine(new Pen(Color.Red, 1), start, new Point(e.X, e.Y)); 
            g.DrawImage(bitmap, pictureBox1.Location.X, pictureBox1.Location.Y, 
           pictureBox1.Width, pictureBox1.Height);
           g.Dispose();
    }
      

  2.   


    我是直接在pictureBox 上画的
    我将你给的程序改成
    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                Bitmap mp=new Bitmap(200,300);
                pictureBox1.Image = mp;
                Graphics g = this.pictureBox1.CreateGraphics();
                g.DrawString("aaaa",new Font ("宋体",12,FontStyle.Bold),Brushes.Red,e.Location);          
                g.Dispose();        }
    后就不对了频繁闪烁 留有残影 而且只有移动的时候才有字体 请问有没有方法改进
      

  3.   

    我的Blog里有用Graphic 画图 文字的例子
    只需要绘制字符串的起始位置换成鼠标在窗体的坐标就行。哦
      

  4.   

    Point p = new Point();private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
      {
      p = e.Location;
      pictureBox1.Invalidate();
      }private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
             e.Graphics.DrawString("aaaa",new Font ("宋体",12,FontStyle.Bold),Brushes.Red,p);
            }