title: C# Drawing on Panels
body: <p>I'm drawing up a day schedule and representing timeslots with panels, and appointments are yet more panels on top.</p>
  
  <p>The user is able to scroll up and down so that the range they can see is shifted earlier or later. When an appointment runs off the end of the visible range, I want there to be a zig-zag indicating that the appointment extends beyond the visible bounds.</p>
  
  <p>I've identified the case where this occurs, and I call a private function <code>drawZigZag(Panel p, int direction);</code> to draw it. The day is spread horizontally, and the direction -1 indicates a zigzag on the left and 1 indicates a zigzag on the right.</p>
  
  <p>So far, I'm not up to the zigzag yet, I'm just experimenting with <code>CreateGraphics()</code> and <code>FillPolygon()</code>. So far I have:</p>
  
  <pre><code>    private void drawZigZag(Panel p, int direction) // 1 = right, -1 = left
      {
          Graphics g = p.CreateGraphics();
  
          g.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.Black)), p.DisplayRectangle);
  
          Point[] points = new Point[4];
  
          points[0] = new Point(0, 0);
          points[1] = new Point(0, p.Height);
          points[2] = new Point(p.Width, p.Height);
          points[3] = new Point(p.Width, 0);
  
          Brush brush = new SolidBrush(Color.DarkGreen);
  
          g.FillPolygon(brush, points);
      }
  </code></pre>
  
  <p>The first <code>FillRectangle()</code> I didn't originally have. I only added that when the <code>FillPolygon()</code> didn't work.</p>
  
  <p>Basically, it's not working and I'm not sure why. The panel is the original colour - it hasn't been filled DarkGreen. I've used <code>CreateGraphics()</code> before for other things, and I'm not really sure why it's not working in this instance. Any ideas?</p>
  
  <p>Edit: Sorry, I thought I should mention: There are several <code>Label</code> controls on my <code>Panel</code> which describe the appointment. These shouldn't be covered if possible.</p>