0% found this document useful (0 votes)
44 views

Graphics: Private Sub Byval As

This document contains code for drawing axes on a graph, handling resizing of the graph, and buttons for plotting a function and resetting the graph. It declares variables for tracking the x and y-axis origins, draws the axes and labels on the graph, and contains event handler code for the plot, reset and resize buttons/events that refresh the graph.

Uploaded by

AR Domingo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Graphics: Private Sub Byval As

This document contains code for drawing axes on a graph, handling resizing of the graph, and buttons for plotting a function and resetting the graph. It declares variables for tracking the x and y-axis origins, draws the axes and labels on the graph, and contains event handler code for the plot, reset and resize buttons/events that refresh the graph.

Uploaded by

AR Domingo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Private Sub DrawAxes(ByVal g As Graphics)

'Note that intXOrigin and intYOrigin is declared as a field variable (class level)
intXOrigin = PicDraw.Width \ 2 'Calculates the x-origin, half of PicDraw Width
intYOrigin = PicDraw.Height \ 2 'Claculates the y-origin, half of PicDraw Height

Dim myfont As New Font("Arial", 8, FontStyle.Regular)

g.Clear(Color.Black)
g.DrawLine(Pens.Gray, 0, intYOrigin, PicDraw.Width, intYOrigin) 'draw x-axis
g.DrawLine(Pens.Gray, intXOrigin, 0, intXOrigin, PicDraw.Height) 'draw y-axis
g.DrawString("(0, 0)", myfont, Brushes.Green, intXOrigin, intYOrigin) 'add label to origin
If blnPlot = False Then
g.DrawString("This program plots the general function" _
& vbNewLine & "y = (Cx)^(1/N)" _
& vbNewLine & "Please input the appropirate values of C and N" _
& vbNewLine & "to the respective textboxes", myfont, Brushes.Green, 0, 0) 'add
instruction
Else
g.DrawString("graph of the function" _
& vbNewLine & "y = (" & sngC & "x)^(1/" & sngN & ")", _
myfont, Brushes.Green, 0, 0) 'adds function label to the graph
End If

End Sub
Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
PicDraw.Refresh() 'for resizing
End Sub

Private Sub btnPlot_Click(sender As System.Object, e As System.EventArgs) Handles


btnPlot.Click
Try
sngN = txtN.Text
sngC = txtConstant.Text
If sngC < 0 Then 'just a checker for C
MessageBox.Show("The constant, C, should be greater than or equal to zero.")
Else 'if everything is right
blnPlot = True
PicDraw.Refresh()
End If
Catch ex As Exception 'oops, something went wrong. ^_^
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles


btnReset.Click
'Just to reset everything
blnPlot = False
PicDraw.Refresh()
txtN.Clear()
txtConstant.Clear()
End Sub
End Class

You might also like