title: Winforms Chart - draw a allowed area on line chart
body: <p>How can I draw the gray area on the chart (allowed range of the signal)?<br>
  I use the Winforms and standard Microsoft <code>System.Windows.Forms.DataVisualization</code> classes.<br>
  It should be the custom range, the meaning that the starting Y point could be not zero only.<br>
  The points I get online, at run time, one by one.</p>
  
  <p>UPDATE:</p>
  
  <p>I tried the StripLine - it's ok, but I don't know how to define the starting point in 2d. It can be set on X only or on Y only. I tried to use the second chart (Area), but it's not what I need...</p>
  
  <p>UPDATE2:<br>
  Thanks to @Reza Aghaei!!!  </p>
  
  <p>Here the code that works great:</p>
  
  <pre><code>void drawAllowedArea(Point startPoint, Point endPoint, PaintEventArgs e)
  {
        var l = (float)chart1.ChartAreas[0].AxisX.ValueToPixelPosition(startPoint.X);
        var t = (float)chart1.ChartAreas[0].AxisY.ValueToPixelPosition(endPoint.Y);
        var r = (float)chart1.ChartAreas[0].AxisX.ValueToPixelPosition(endPoint.X);
        var b = (float)chart1.ChartAreas[0].AxisY.ValueToPixelPosition(startPoint.Y);
        var rect = RectangleF.FromLTRB(l, t, r, b);
        using (var br = new SolidBrush(Color.FromArgb(100, Color.Blue))) 
        {
             e.Graphics.FillRectangle(br, rect.X, rect.Y, rect.Width, rect.Height);
        }
        e.Graphics.DrawRectangle(Pens.Red, rect.X, rect.Y, rect.Width, rect.Height);
  }
  
  //and use this function in chart1_Paint event:
  void chart1_Paint(object sender, PaintEventArgs e)
  {
        drawAllowedArea(new Point(20, 50000), new Point(40, 100000), e);
  }
  </code></pre>
  
  <p>END OF UPDATE ---------------------------------------------------------</p>
  
  <p><a href="https://i.stack.imgur.com/RHT8e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RHT8e.png" alt="enter image description here"></a></p>
  
  <p>Thank you a lot!</p>