title: DashDot/Dash style within Windows Forms drawn incorrectly and Panels vs ShapeContainers
body: <p>I'm creating an UI with a panel(<code>System.Windows.Forms.Panel</code>) which will contain a Rectangle/Ellipse and the size(width/height) of the shape is dependent on the horizontal and vertical sliders. The code below does achieve to some extent the desired behavior. However, A line representing the centre of the panel with no Style works fine whereas a style of <code>DashDot</code> or <code>Dash</code> results in lines drawn across the diagonals and sides of the panels instead of the specified points(startPoint, endPoint). Is there a way to centre the rectangle based on the size of the panel?</p>
  
  <pre><code>private void vScroll_Scroll(object sender, ScrollEventArgs e)
  {
      this.vScrollValue.Text = vScrollBar.Value.ToString();
      panel.Invalidate(/*myRectangle*/);
  }
  
  private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
  {
      this.hScrollValue.Text = hScrollBar.Value.ToString();
      panel.Invalidate(/*myRectangle*/);
  }
  
  private void panel_Paint(object sender, PaintEventArgs e)
  {
      myRectangle = new Rectangle(90, 90, hScrollBar.Value, vScrollBar.Value);
      System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
      messageBoxCS.AppendFormat("panel.Location.X = {0} panel.Location.Y = {1} (panel.Size.Height/2) = {2}", panel.Location.X, panel.Location.Y, e.ClipRectangle);
      //MessageBox.Show(messageBoxCS.ToString(), "Panel Paint");
      //Panel's midpoint (location(x,y) = 88,44, Size(x,y) = 182,184)
      Point startPoint = new Point(e.ClipRectangle.Location.X, e.ClipRectangle.Location.Y + (e.ClipRectangle.Size.Height / 2));
      Point endPoint = new Point(e.ClipRectangle.Location.X + e.ClipRectangle.Size.Width,     e.ClipRectangle.Location.Y + (e.ClipRectangle.Size.Height / 2));
  
      Pen dashRed = Pens.Red;
      e.Graphics.DrawRectangle(Pens.Black, myRectangle);
      //dashRed.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
      e.Graphics.DrawLine(Pens.Red, startPoint, endPoint); 
  }
  </code></pre>
  
  <p>Within the <code>InitializeComponent()</code> method the paintHandler event is registered as follows:</p>
  
  <pre><code> this.panel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_Paint);
  </code></pre>
  
  <p>Also, being new to C#, Should I be using <code>Micorsoft.VisualBasic.Powerpack</code> - ShapeContainers/RectangleShape/EllipseShape instead of using the WinForms.Panel?</p>