Imports System.Text.RegularExpressions
Public Class Form1
Private Function GetDecimalPlaces(ByVal Number As Double) As Int16
Dim SNumber As String = Number.ToString
Dim DecimalSeparator As String = My.Application.Culture.NumberFormat.CurrencyDecimalSeparator
If SNumber.IndexOf(DecimalSeparator) > -1 Then
SNumber = SNumber.Remove(0, SNumber.IndexOf(DecimalSeparator) + 1)
Return SNumber.Length
Else
Return 0
End If
End Function
Private Sub ResetIncrement()
nudIncrement.Minimum = (nudMax.Value - nudMin.Value) / 100
nudIncrement.Maximum = (nudMax.Value - nudMin.Value) / 2
nudDrawValueIncrement.Maximum = nudIncrement.Maximum
nudDrawValueIncrement.Minimum = nudIncrement.Minimum
End Sub
Private Sub nudPixelsPerDot_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudPixelsPerDot.ValueChanged
gaGraph.PixelsPerDot = nudPixelsPerDot.Value
End Sub
Private Sub txtAxisColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAxisColor.Click
Dim ColDialog As New ColorDialog
If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
txtAxisColor.BackColor = ColDialog.Color
txtAxisColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
txtAxisColor.Text = ColDialog.Color.ToKnownColor.ToString
gaGraph.AxisColor = ColDialog.Color
End If
End Sub
Private Sub txtFunctionColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFunctionColor.Click
Dim ColDialog As New ColorDialog
If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
txtFunctionColor.BackColor = ColDialog.Color
txtFunctionColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
txtFunctionColor.Text = ColDialog.Color.ToKnownColor.ToString
gaGraph.FunctionColor = ColDialog.Color
End If
End Sub
Private Sub cmdRedraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRedraw.Click
gaGraph.Refresh()
End Sub
Private Sub nudMin_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMin.ValueChanged
If nudMin.Value > nudMax.Value Then
If Me.Visible Then
MessageBox.Show("Valore non valido!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
nudMin.Value = nudMax.Value
Else
ResetIncrement()
End If
End Sub
Private Sub nudMax_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMax.ValueChanged
If nudMax.Value < nudMin.Value Then
If Me.Visible Then
MessageBox.Show("Valore non valido!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
nudMax.Value = nudMin.Value
Else
ResetIncrement()
End If
End Sub
Private Sub cmdDrawFunction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrawFunction.Click
Try
gaGraph.DrawFunction(txtExpression.Text, nudMin.Value, nudMax.Value, nudIncrement.Value)
gaGraph.Refresh()
Catch OE As OverflowException
MessageBox.Show("Overflow di un'operazione aritmetica! Il problema puo' essere stato causato da :" & vbCrLf & _
"- radici quadrate con radicandi negativi;" & vbCrLf & _
"- logaritmi con parametro 0;" & vbCrLf & _
"- tangenti con parametro pi mezzi;" & vbCrLf & _
"- una qualsiasi funzione il cui parametro presenta soluzioni impossibili;" & vbCrLf & _
"- una qualsiasi funzione il cui parametro produce soluzioni con valore troppo elevato" & vbCrLf & _
"Controllare che x sia compreso nel corretto campo di esistenza!", _
"MGraphing - Errore di overflow", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch AE As ArgumentException
MessageBox.Show("L'espressione non e' valida! Controllare nell'espressione: " & vbCrLf & _
"- che gli operatori siano scritti in maniera corretta;" & vbCrLf & _
"- che tutte le parentesi siano chiuse correttamente;" & vbCrLf & _
"- che tutte le funzioni siano supportate dal programma;" & vbCrLf & _
"- che non ci siano coefficienti letterali, o numerici senza l'operatore *.", _
"MGraphing - Errore di parsing", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub chbAccurateLine_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbAccurateLine.CheckedChanged
gaGraph.AccurateLine = chbAccurateLine.Checked
End Sub
Private Sub txtCoords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCoords.Click
Dim X As String = InputBox("Inserire il valore di x, in pixel:", "MGraphing", gaGraph.Center.X)
Dim Y As String = InputBox("Inserire il valore di y, in pixel:", "MGraphing", gaGraph.Center.Y)
Dim Number As New Regex("\d+")
If Number.IsMatch(X) And Number.IsMatch(Y) Then
gaGraph.Center = New Point(CInt(X), CInt(Y))
txtCoords.Text = X & "; " & Y
gaGraph.Refresh()
Else
MessageBox.Show("Valore errato!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
gaGraph.Save()
End Sub
Private Sub cmdAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAbout.Click
Dim A As New frmAbout
A.ShowDialog()
End Sub
Private Sub nudDrawValueIncrement_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudDrawValueIncrement.ValueChanged
gaGraph.DrawValueIncrement = nudDrawValueIncrement.Value
End Sub
Private Sub chbDrawValues_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbDrawValues.CheckedChanged
gaGraph.DrawValues = chbDrawValues.Checked
End Sub
Private Sub strChangeErrors_CheckedChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strChangeErrors.CheckedChanged
gaGraph.LaunchExceptionOnDrawError = strChangeErrors.Checked
End Sub
Private Sub strStartInZero_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strStartInZero.CheckedChanged
gaGraph.StartInZero = strStartInZero.Checked
End Sub
Private Sub chbShowGrid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbShowGrid.CheckedChanged
gaGraph.ShowGridLines = chbShowGrid.Checked
End Sub
Private Sub txtGridColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGridColor.Click
Dim ColDialog As New ColorDialog
If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
txtGridColor.BackColor = ColDialog.Color
txtGridColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
txtGridColor.Text = ColDialog.Color.ToKnownColor.ToString
gaGraph.GridLinesColor = ColDialog.Color
End If
End Sub
End Class