Public Class Form1
Private xmin, xmax, ymin, ymax, w, h As Integer
Private bmp As Bitmap
Private g As Graphics
Private pnAxis, pnGraphics As Pen
Private pnt As List(Of PointF), pp As PointF
Private isDraw As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
xmin = -7 : xmax = 7 : ymin = -2 : ymax = 2
w = PictureBox1.Width
h = PictureBox1.Height
bmp = New Bitmap(w, h, PictureBox1.CreateGraphics())
PictureBox1.Enabled = False
pnAxis = New Pen(Brushes.Blue, -1)
pnGraphics = New Pen(Brushes.Red, 2)
Button1.Enabled = False
Label2.Text = "min = " & xmin.ToString
Label3.Text = "max = " & xmax.ToString
Label5.Text = "min = " & ymin.ToString
Label4.Text = "max = " & ymax.ToString
Label1.Text = "X"
Label6.Text = "Y"
Label7.Text = "Интегралл"
Label8.Text = ""
End Sub
Private Sub CreateGraphics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PictureBox1.Enabled = True
gettingStartedCanvas()
Button1.Enabled = True
Label8.Text = ""
End Sub
Private Sub GetIntegral_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim kx As Double = w / 2 / xmax
Dim ky As Double = h / 2 / ymax
Dim p As PointF
For i = 0 To pnt.Count - 1
p = pnt(i)
p.X -= w / 2
p.Y -= h / 2
p.Y = -p.Y
p.X /= kx
p.Y /= ky
pnt(i) = p
Next
'вычисляем приближенно по методу трапеций
Dim sum As Double = 0.0
For i = 1 To pnt.Count - 1
sum += (pnt(i - 1).Y + pnt(i).Y) / 2 * (pnt(i).X - pnt(i - 1).X)
Next
Label8.Text = sum.ToString
Button1.Enabled = False
PictureBox1.Enabled = False
End Sub
Private Sub gettingStartedCanvas()
g = Graphics.FromImage(bmp)
g.Clear(PictureBox1.BackColor)
g.DrawLine(pnAxis, New Point(w / 2, 0), New Point(w / 2, h))
g.DrawLine(pnAxis, New Point(0, h / 2), New Point(w, h / 2))
PictureBox1.Image = bmp
g.Dispose()
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim x As Integer = e.Location.X
Dim y As Integer = e.Location.Y
If x <> 0 Then x = 0
pnt = New List(Of PointF)
pp = New PointF(x, y)
pnt.Add(pp)
isDraw = True
g = Graphics.FromImage(bmp)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If Not isDraw Then Exit Sub
Dim x As Integer = e.Location.X
Dim y As Integer = e.Location.Y
If x <> w Then x = w
pnt.Add(New PointF(x, y))
g.DrawLine(pnGraphics, pp, pnt(pnt.Count - 1))
isDraw = False
g.Dispose()
PictureBox1.Image = bmp
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If isDraw Then
Dim x As Integer = e.Location.X
Dim y As Integer = e.Location.Y
If x <= pp.X Then Exit Sub
Dim p As PointF = New PointF(x, y)
g.DrawLine(pnGraphics, pp, p)
pnt.Add(p)
pp = p
PictureBox1.Image = bmp
End If
End Sub
End Class