Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should create a custom UserControl and use the Paint even to draw on the surface of the control. The Paint event provides you with a Graphics object which you can use to draw the graph. The big thing to know, however, is that you will need to swap your Y axis. In windows, the top-left of the screen is 0,0 rather than the bottom-left.</p> <p>So, for instance, the following code will draw the x and y axis of a graph on a contorl:</p> <pre><code>Public Class CartesianGraph Public Property BottomLeftExtent() As Point Get Return _bottomLeftExtent End Get Set(ByVal value As Point) _bottomLeftExtent = value End Set End Property Private _bottomLeftExtent As Point = New Point(-100, -100) Public Property TopRightExtent() As Point Get Return _topRightExtent End Get Set(ByVal value As Point) _topRightExtent = value End Set End Property Private _topRightExtent As Point = New Point(100, 100) Private Sub CartesianGraph_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim extentHeight As Integer = _topRightExtent.Y - _bottomLeftExtent.Y Dim extentWidth As Integer = _topRightExtent.X - _bottomLeftExtent.X If (extentHeight &lt;&gt; 0) And (extentWidth &lt;&gt; 0) Then If (_bottomLeftExtent.Y &lt;= 0) And (_topRightExtent.Y &gt;= 0) Then Dim xAxis As Integer = e.ClipRectangle.Height - (_bottomLeftExtent.Y * -1 * e.ClipRectangle.Height \ extentHeight) e.Graphics.DrawLine(New Pen(ForeColor), 0, xAxis, e.ClipRectangle.Width, xAxis) End If If (_bottomLeftExtent.X &lt;= 0) And (_topRightExtent.X &gt;= 0) Then Dim yAxis As Integer = e.ClipRectangle.Width * _bottomLeftExtent.X * -1 \ extentWidth e.Graphics.DrawLine(New Pen(ForeColor), yAxis, 0, yAxis, e.ClipRectangle.Height) End If End If End Sub End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload