Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MGraphing - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports System.Text.RegularExpressions
  2. Public Class Form1
  3.     Private Function GetDecimalPlaces(ByVal Number As Double) As Int16
  4.         Dim SNumber As String = Number.ToString
  5.         Dim DecimalSeparator As String = My.Application.Culture.NumberFormat.CurrencyDecimalSeparator
  6.  
  7.         If SNumber.IndexOf(DecimalSeparator) > -1 Then
  8.             SNumber = SNumber.Remove(0, SNumber.IndexOf(DecimalSeparator) + 1)
  9.             Return SNumber.Length
  10.         Else
  11.             Return 0
  12.         End If
  13.     End Function
  14.  
  15.     Private Sub ResetIncrement()
  16.         nudIncrement.Minimum = (nudMax.Value - nudMin.Value) / 100
  17.         nudIncrement.Maximum = (nudMax.Value - nudMin.Value) / 2
  18.         nudDrawValueIncrement.Maximum = nudIncrement.Maximum
  19.         nudDrawValueIncrement.Minimum = nudIncrement.Minimum
  20.     End Sub
  21.  
  22.     Private Sub nudPixelsPerDot_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudPixelsPerDot.ValueChanged
  23.         gaGraph.PixelsPerDot = nudPixelsPerDot.Value
  24.     End Sub
  25.  
  26.     Private Sub txtAxisColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAxisColor.Click
  27.         Dim ColDialog As New ColorDialog
  28.         If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  29.             txtAxisColor.BackColor = ColDialog.Color
  30.             txtAxisColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
  31.             txtAxisColor.Text = ColDialog.Color.ToKnownColor.ToString
  32.             gaGraph.AxisColor = ColDialog.Color
  33.         End If
  34.     End Sub
  35.  
  36.     Private Sub txtFunctionColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFunctionColor.Click
  37.         Dim ColDialog As New ColorDialog
  38.         If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  39.             txtFunctionColor.BackColor = ColDialog.Color
  40.             txtFunctionColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
  41.             txtFunctionColor.Text = ColDialog.Color.ToKnownColor.ToString
  42.             gaGraph.FunctionColor = ColDialog.Color
  43.         End If
  44.     End Sub
  45.  
  46.     Private Sub cmdRedraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRedraw.Click
  47.         gaGraph.Refresh()
  48.     End Sub
  49.  
  50.     Private Sub nudMin_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMin.ValueChanged
  51.         If nudMin.Value > nudMax.Value Then
  52.             If Me.Visible Then
  53.                 MessageBox.Show("Valore non valido!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  54.             End If
  55.             nudMin.Value = nudMax.Value
  56.         Else
  57.             ResetIncrement()
  58.         End If
  59.     End Sub
  60.  
  61.     Private Sub nudMax_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMax.ValueChanged
  62.         If nudMax.Value < nudMin.Value Then
  63.             If Me.Visible Then
  64.                 MessageBox.Show("Valore non valido!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  65.             End If
  66.             nudMax.Value = nudMin.Value
  67.         Else
  68.             ResetIncrement()
  69.         End If
  70.     End Sub
  71.  
  72.     Private Sub cmdDrawFunction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrawFunction.Click
  73.         Try
  74.             gaGraph.DrawFunction(txtExpression.Text, nudMin.Value, nudMax.Value, nudIncrement.Value)
  75.             gaGraph.Refresh()
  76.         Catch OE As OverflowException
  77.             MessageBox.Show("Overflow di un'operazione aritmetica! Il problema puo' essere stato causato da :" & vbCrLf & _
  78.             "- radici quadrate con radicandi negativi;" & vbCrLf & _
  79.             "- logaritmi con parametro 0;" & vbCrLf & _
  80.             "- tangenti con parametro pi mezzi;" & vbCrLf & _
  81.             "- una qualsiasi funzione il cui parametro presenta soluzioni impossibili;" & vbCrLf & _
  82.             "- una qualsiasi funzione il cui parametro produce soluzioni con valore troppo elevato" & vbCrLf & _
  83.             "Controllare che x sia compreso nel corretto campo di esistenza!", _
  84.             "MGraphing - Errore di overflow", MessageBoxButtons.OK, MessageBoxIcon.Error)
  85.         Catch AE As ArgumentException
  86.             MessageBox.Show("L'espressione non e' valida! Controllare nell'espressione: " & vbCrLf & _
  87.             "- che gli operatori siano scritti in maniera corretta;" & vbCrLf & _
  88.             "- che tutte le parentesi siano chiuse correttamente;" & vbCrLf & _
  89.             "- che tutte le funzioni siano supportate dal programma;" & vbCrLf & _
  90.             "- che non ci siano coefficienti letterali, o numerici senza l'operatore *.", _
  91.             "MGraphing - Errore di parsing", MessageBoxButtons.OK, MessageBoxIcon.Error)
  92.         End Try
  93.     End Sub
  94.  
  95.     Private Sub chbAccurateLine_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbAccurateLine.CheckedChanged
  96.         gaGraph.AccurateLine = chbAccurateLine.Checked
  97.     End Sub
  98.  
  99.     Private Sub txtCoords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCoords.Click
  100.         Dim X As String = InputBox("Inserire il valore di x, in pixel:", "MGraphing", gaGraph.Center.X)
  101.         Dim Y As String = InputBox("Inserire il valore di y, in pixel:", "MGraphing", gaGraph.Center.Y)
  102.         Dim Number As New Regex("\d+")
  103.  
  104.         If Number.IsMatch(X) And Number.IsMatch(Y) Then
  105.             gaGraph.Center = New Point(CInt(X), CInt(Y))
  106.             txtCoords.Text = X & "; " & Y
  107.             gaGraph.Refresh()
  108.         Else
  109.             MessageBox.Show("Valore errato!", "MGraphing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  110.         End If
  111.     End Sub
  112.  
  113.     Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
  114.         gaGraph.Save()
  115.     End Sub
  116.  
  117.     Private Sub cmdAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAbout.Click
  118.         Dim A As New frmAbout
  119.         A.ShowDialog()
  120.     End Sub
  121.  
  122.     Private Sub nudDrawValueIncrement_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudDrawValueIncrement.ValueChanged
  123.         gaGraph.DrawValueIncrement = nudDrawValueIncrement.Value
  124.     End Sub
  125.  
  126.     Private Sub chbDrawValues_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbDrawValues.CheckedChanged
  127.         gaGraph.DrawValues = chbDrawValues.Checked
  128.     End Sub
  129.  
  130.     Private Sub strChangeErrors_CheckedChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strChangeErrors.CheckedChanged
  131.         gaGraph.LaunchExceptionOnDrawError = strChangeErrors.Checked
  132.     End Sub
  133.  
  134.     Private Sub strStartInZero_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strStartInZero.CheckedChanged
  135.         gaGraph.StartInZero = strStartInZero.Checked
  136.     End Sub
  137.  
  138.     Private Sub chbShowGrid_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbShowGrid.CheckedChanged
  139.         gaGraph.ShowGridLines = chbShowGrid.Checked
  140.     End Sub
  141.  
  142.     Private Sub txtGridColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGridColor.Click
  143.         Dim ColDialog As New ColorDialog
  144.         If ColDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  145.             txtGridColor.BackColor = ColDialog.Color
  146.             txtGridColor.ForeColor = Color.FromArgb(Not ColDialog.Color.ToArgb)
  147.             txtGridColor.Text = ColDialog.Color.ToKnownColor.ToString
  148.             gaGraph.GridLinesColor = ColDialog.Color
  149.         End If
  150.     End Sub
  151. End Class