title: Graphics flickering when using Panel paint event
body: <p>I created an analog clock that will work properly according to real time.</p>
  
  <p>I don't want you to solve it for me or anything - my code is already working, but it's flickering heavily and with my limited knowledge I wasn't able to determine what exactly it is I need to change to stop the flicker.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace ClockAndStuff
  {
  
      public partial class TheName : Form
      {
  
          public TheName()
          {
              InitializeComponent();
              timer1.Start();
          }
  
          private void panel1_Paint(object sender, PaintEventArgs e)
          {
              Graphics surfaceBckg;
              Graphics surfaceMin;
              Graphics surfaceH;
              Graphics surfaceSec;
  
              Pen penMin = new Pen(Color.Pink,2);
              Pen penH = new Pen(Color.Red,3);
              Pen penSec = new Pen(Color.DeepPink,1);
              Pen black = new Pen(Color.Black, 4F);
  
              surfaceBckg = panel1.CreateGraphics();
              surfaceBckg.TranslateTransform(250, 250);
              surfaceBckg.DrawEllipse(black,-220,-220,440,440);
  
              surfaceMin = panel1.CreateGraphics();
              surfaceMin.TranslateTransform(250, 250);
              surfaceMin.RotateTransform(6 * DateTime.Now.Minute);
  
              surfaceH = panel1.CreateGraphics();
              surfaceH.TranslateTransform(250, 250);
              surfaceH.RotateTransform(30 * DateTime.Now.Hour);
  
              surfaceSec = panel1.CreateGraphics();
              surfaceSec.TranslateTransform(250, 250);
              surfaceSec.RotateTransform(6 * DateTime.Now.Second);
  
              surfaceMin.DrawLine(penMin, 0, 0, 0, -200);
              surfaceH.DrawLine(penH, 0, 0, 0, -120);
              surfaceSec.DrawLine(penSec, 0, 0, 1, -180);
          }
  
          private void timer1_Tick(object sender, EventArgs e)
          {
              panel1.Refresh();
          } 
      }
  }
  </code></pre>
  
  <p>It's correct according to my assignment, but I can't help but to think there must be better way to do it. </p>
  
  <p>I'm not yet big on C# so if you could give me code sample as an answer there's bigger possibility I'll be able to get to understand it...</p>
  
  <p><img src="https://i.stack.imgur.com/JkjWk.png" alt="This is what it looks like"></p>