先贴代码:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.MouseWheel += new MouseEventHandler(pbMain_MouseWheel);
            this.MouseDown += new MouseEventHandler(pbMain_MouseDown);
            this.MouseUp += new MouseEventHandler(pbMain_MouseUp);
            blackPen = new Pen(Color.Black, 1);
        }
        private int R = 20;
        private Pen blackPen;
        private Point centerPoint = new Point();
        private bool bStart = false;        private void pbMain_MouseDown(object sender, MouseEventArgs e)
        {
            centerPoint.X = e.X;
            centerPoint.Y = e.Y;
            bStart = true;
        }
        private void pbMain_MouseUp(object sender, MouseEventArgs e)
        {
            bStart = false;
        }
        private void pbMain_MouseWheel(object sender, MouseEventArgs e)
        {
            if (bStart)
            {
                int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
                R += numberOfTextLinesToMove;
                if(R < 0) R = 0;
                if(R > 60) R = 60;
                Graphics g = this.CreateGraphics();
                g.DrawEllipse(blackPen, pointTopLeft.X - R, pointTopLeft.Y - R, 2 * R, 2 * R);
            }
        }
     }
//////////////////////////////////////////////////////////////////////
简化在程序如上:按下鼠标右键(不松开),此时,滚动鼠标滚轮,将在窗口内绘制多个不同直径在同心圆。
我的问题是:如何才能始终只画一个圆?
            考虑到在复杂背景下画圆的情况,如背景是一幅图,不能使用Graphics的Clear函数清除背景。

解决方案 »

  1.   

    每次画的时候先把前一次画的擦掉。
    你的pointTopLeft哪来的。
      

  2.   


    不好意思,贴的时候没有注意, pointTopLeft 就是 centerPoint另外,问题就是如何擦掉前一次画的。
      

  3.   


    这个方法应该可行,但有个问题:如果有一幅图像作为背景,每次都重画一次原图,代价太大,也可能造成闪烁。考虑到以上情况,我没有尝试这种方法。以前读书的时候,好像有做两次异或运算,可以擦掉前一次画的线。但在C#中,xor仅有region类包含,且不会用,正在琢磨中。
      

  4.   

    只能用异或原地重画来还原背景,但是貌似GDI+没这个功能
    只有调用GDI的API函数咯
      

  5.   


    你的方法可行,谢谢。问题已解决:
    在pbMain_MouseWheel()函数的Graphics g = this.CreateGraphics();语句前加入以下代码,即可this.Refresh();若鼠标事件是基于如pictureBox这样在控件,则相应改为:this.pictureBox1.Refresh();有没有Refresh()函数在原型代码?