Public Class Funktionsplotter Dim berechnet As Boolean = False Private Function F(ByVal x As Single) As Single F = x * x End Function Private Function G(ByVal x As Single) As Single If (x < 10) Then G = 5 * x Else G = 20 * x - 150 End If End Function Private Sub ButtonEnde_Click(sender As System.Object, e As System.EventArgs) Handles ButtonEnde.Click Me.Close() End Sub Private Sub ButtonBerechnen_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBerechnen.Click REM Berechnen Dim x, y As Single For x = 0 To 20 Step 0.1 y = F(x) - G(x) ListBox1.Items.Add(Format(x, "00.0") + vbTab + Format(y, "000.00")) Next berechnet = True Me.Invalidate() End Sub Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim x, y As Single Dim xpos, ypos As Integer If (berechnet) Then Dim whiteBrush As New Drawing.SolidBrush(Color.White) Dim blackPen As New Drawing.Pen(Color.Black, 1) Dim fontObj As Font fontObj = New System.Drawing.Font("Times", 10, FontStyle.Bold) e.Graphics.FillRectangle(whiteBrush, 180, 30, 320, 280) e.Graphics.DrawLine(blackPen, 180, 170, 500, 170) e.Graphics.DrawLine(blackPen, 180, 30, 180, 310) e.Graphics.DrawString("Plot", fontObj, Brushes.Black, 190, 40) REM Urspung bei 180,170 x-Ausdehnung: +320, y-Ausdehnung: -140, +140 For x = 0 To 20 Step 0.1 y = F(x) - G(x) xpos = 180 + x / 20 * 320 ypos = 170 - (y / 150) * 140 e.Graphics.DrawLine(blackPen, xpos, 170, xpos, ypos) Next End If End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class