我想画的是一条一段固定一端旋转的线段。
下面是绘图代码。我已经用了双缓存了啊!可还是闪烁。怎么解决啊?void Timers_Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {                                     
                double x = 200 + 100* Math.Sin(num * Math.PI / 180);
                double y = 120 - 100 * Math.Cos(num * Math.PI / 180);
                label1.Text = Convert.ToString((num = num + 0.1)); //显示到lable              
                Graphics p = pictureBox1.CreateGraphics();
                Bitmap bmp = new Bitmap(600, 600);
                Graphics g = Graphics.FromImage(bmp);               g.DrawLine(new Pen(Color.Black), (float)200, (float)120, (float)x, (float)y);
               p.DrawLine(new Pen(Color.Black), (float)200, (float) 120, (float)x, (float)y);
               pictureBox1.CreateGraphics().DrawImage(bmp, 0, 0);                pictureBox1.Invalidate();
        }控件c#图形

解决方案 »

  1.   


    private Bitmap memoryCanvas;Form Load Event: init
        memoryCanvas=new Bitmap(pictureBox1.Width,pictureBox1.Height); void Timers_Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {                                     
          double x = 200 + 100* Math.Sin(num * Math.PI / 180);
          double y = 120 - 100 * Math.Cos(num * Math.PI / 180);
          label1.Text = Convert.ToString((num = num + 0.1));      Graphics memDc=Graphics.FromImage(memoryCanvas);        memDc.Clear(pictureBox1.BackColor);           
          memDc.DrawLine(new Pen(Color.Black), (float)200, (float)120, (float)x, (float)y);
          memDc.DrawLine(new Pen(Color.Black), (float)200, (float) 120, (float)x, (float)y);
          pictureBox1.Image=memoryCanvas;      memDc.Dispose();
    }Release:
        memoryCanvas.Dispose();
      

  2.   

    参考项目中的skinPicturebox控件和SkinAnimatorImg控件
    (360安全卫士DEMO)点击下载
    (高仿QQ2013通讯DEMO-10.30更新)点击下载
      

  3.   

    在 Paint事件中绘图。g应来自事件e。     
       private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                Random r = new Random();            double num = r.NextDouble() * 10;            double x = 200 + 100 * Math.Sin(num * Math.PI / 180);
                double y = 120 - 100 * Math.Cos(num * Math.PI / 180);
                label1.Text = Convert.ToString((num = num + 0.1)); //显示到lable              
                Graphics p = e.Graphics;
                //Bitmap bmp = new Bitmap(600, 600);
                //Graphics g = Graphics.FromImage(bmp);            //g.DrawLine(new Pen(Color.Black), (float)200, (float)120, (float)x, (float)y);
                p.DrawLine(new Pen(Color.Black), (float)200, (float)120, (float)x, (float)y);
                //pictureBox1.CreateGraphics().DrawImage(bmp, 0, 0);
            }
      

  4.   

    时钟的事件变为:        
    void Timers_Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
          pictureBox1.Invalidate();
    }
    上面代码中的num我也不知道是什么,给了个随机数。
      

  5.   

    如果希望将所有绘图缓冲在位图上,然后再绘制,可以
            private Bitmap bmp;
            private void timer1_Tick(object sender, EventArgs e)
            {
                Random r = new Random();
                double num = r.NextDouble() * 10;
                double x = 200 + 100 * Math.Sin(num * Math.PI / 180);
                double y = 120 - 100 * Math.Cos(num * Math.PI / 180);
                label1.Text = Convert.ToString((num = num + 0.1)); //显示到lable              
                bmp = new Bitmap(600, 600);
                Graphics g = Graphics.FromImage(bmp);
                g.DrawLine(new Pen(Color.Black), (float)200, (float)120, (float)x, (float)y);
                pictureBox1.Invalidate();
            }        private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                if (bmp != null)
                {
                    e.Graphics.DrawImage(bmp, 0, 0);
                }
            }