-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath_Graphics.vb
More file actions
244 lines (209 loc) · 10.1 KB
/
Math_Graphics.vb
File metadata and controls
244 lines (209 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Imports System.Windows.Forms
Imports System.Drawing
Imports MathNet.Symbolics
Imports MathNet.Numerics.LinearAlgebra
Imports NCalc
Imports Expression = NCalc.Expression
Imports System.Web.ModelBinding
Public Class Math_Graphics
Private zoom As Double = 1.0
Private offsetX As Double = 0.0
Private offsetY As Double = 0.0
Private step1 As Integer = 50 ' Passo iniziale
Private scaleFactor As Single = 1
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
Dim width As Integer = Me.ClientSize.Width
Dim height As Integer = Me.ClientSize.Height
End Sub
Private Sub DrawGraph(ByVal g As Graphics)
' Calcola il range degli assi x e y
Dim xMin As Double = -10.0 * zoom + offsetX
Dim xMax As Double = 10.0 * zoom + offsetX
Dim yMin As Double = -10.0 * zoom + offsetY
Dim yMax As Double = 10.0 * zoom + offsetY
' Calcola la larghezza e l'altezza della finestra di disegno
Dim width As Integer = Me.ClientSize.Width
Dim height As Integer = Me.ClientSize.Height
' Disegna gli assi x e y
Dim xAxis As Point() = {New Point(0, height / 2), New Point(width, height / 2)}
Dim yAxis As Point() = {New Point(width / 2, 0), New Point(width / 2, height)}
' Converti il colore delle impostazioni in un oggetto Pen
Dim textColorPen As New Pen(My.Settings.TextColor)
' Disegna le linee utilizzando il colore definito nelle impostazioni del testo
g.DrawLines(textColorPen, xAxis)
g.DrawLines(textColorPen, yAxis)
' Itera su ogni punto sull'asse x
For x As Double = xMin To xMax Step 0.01
If Not String.IsNullOrEmpty(TextBox1.Text) Then
Dim expr As New Expression(TextBox1.Text)
expr.Parameters("x") = x
If TextBox1.Text.Contains("y") Then
For y As Double = yMin To yMax Step 0.01
expr.Parameters("y") = y
Dim result As Double = expr.Evaluate()
' Calcola il corrispondente punto sull'asse x e y
Dim screenX As Integer = (x - xMin) / (xMax - xMin) * (width - 1)
Dim screenY As Integer = (yMax - y) / (yMax - yMin) * (height - 1)
' Disegna il punto
g.DrawRectangle(textColorPen, screenX, screenY, 1, 1)
Next
Else
' Calcola il corrispondente punto sull'asse y
Dim y As Double = expr.Evaluate()
Dim screenX As Integer = (x - xMin) / (xMax - xMin) * (width - 1)
Dim screenY As Integer = (yMax - y) / (yMax - yMin) * (height - 1)
' Disegna il punto
g.DrawRectangle(textColorPen, screenX, screenY, 1, 1)
End If
End If
Next
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
DrawGraph(e.Graphics)
End Sub
Private Sub ApplyMenuColors(menu As MenuStrip)
' Applica i colori di sfondo e del testo del menu
menu.BackColor = My.Settings.BackgroundColor
menu.ForeColor = My.Settings.TextColor
' Itera attraverso tutti gli elementi del menu
For Each item As ToolStripItem In menu.Items
' Controlla se l'elemento è un ToolStripMenuItem
If TypeOf item Is ToolStripMenuItem Then
' Applica i colori di sfondo e del testo al ToolStripMenuItem
Dim menuItem As ToolStripMenuItem = CType(item, ToolStripMenuItem)
menuItem.BackColor = My.Settings.BackgroundColor
menuItem.ForeColor = My.Settings.TextColor
' Applica ricorsivamente i colori agli elementi figlio del ToolStripMenuItem
ApplyMenuColorsToItems(menuItem)
ElseIf TypeOf item Is ToolStripTextBox Then
' Se l'elemento è un ToolStripTextBox, applica i colori appropriati
Dim toolStripTextBox As ToolStripTextBox = CType(item, ToolStripTextBox)
toolStripTextBox.BackColor = My.Settings.BackgroundColor
toolStripTextBox.ForeColor = My.Settings.TextColor
End If
Next
End Sub
Private Sub ApplyMenuColorsToItems(menuItem As ToolStripMenuItem)
' Itera attraverso gli elementi figlio del ToolStripMenuItem
For Each subItem As ToolStripItem In menuItem.DropDownItems
' Controlla se l'elemento figlio è un ToolStripMenuItem
If TypeOf subItem Is ToolStripMenuItem Then
' Applica i colori di sfondo e del testo al ToolStripMenuItem figlio
Dim subMenuItem As ToolStripMenuItem = CType(subItem, ToolStripMenuItem)
subMenuItem.BackColor = My.Settings.BackgroundColor
subMenuItem.ForeColor = My.Settings.TextColor
' Applica ricorsivamente i colori agli elementi figlio del ToolStripMenuItem figlio
ApplyMenuColorsToItems(subMenuItem)
ElseIf TypeOf subItem Is ToolStripTextBox Then
' Se l'elemento figlio è un ToolStripTextBox, applica i colori appropriati
Dim toolStripTextBox As ToolStripTextBox = CType(subItem, ToolStripTextBox)
toolStripTextBox.BackColor = My.Settings.BackgroundColor
toolStripTextBox.ForeColor = My.Settings.TextColor
End If
Next
End Sub
Private Sub Math_Graphics_Load(sender As Object, e As EventArgs) Handles MyBase.Load
My.Settings.Reload()
ApplyMenuColors(MenuStrip1)
Me.ForeColor = My.Settings.TextColor
Me.BackColor = My.Settings.BackgroundColor
' Imposta la lingua iniziale
Dim linguaSelezionata As String = System.Configuration.ConfigurationManager.AppSettings("Lingua")
If linguaSelezionata = "English" Then
Button1.Text = "Clear"
CalculatorToolStripMenuItem.Text = "Calculator"
If FastMenu.Visible = True Then
FastMenuToolStripMenuItem.Text = "Fast Menu (Close)"
Else
FastMenuToolStripMenuItem.Text = "Fast Menu"
End If
AboutToolStripMenuItem.Text = "About"
SettingsToolStripMenuItem.Text = "Settings"
Button1.Text = "REFRESH"
Button2.Text = "CLEAR"
btnZoomIn.Text = "ZOOM IN"
btnZoomOut.Text = "ZOOM OUT"
btnMoveUp.Text = "MOVE UP"
btnMoveDown.Text = "MOVE DOWN"
btnMoveLeft.Text = "MOVE LEFT"
btnMoveRight.Text = "MOVE RIGHT"
ElseIf linguaSelezionata = "Italian" Then
Button1.Text = "C"
CalculatorToolStripMenuItem.Text = "Calcolatrici"
FastMenuToolStripMenuItem.Text = "Menu Veloce"
AboutToolStripMenuItem.Text = "Informazioni su"
SettingsToolStripMenuItem.Text = "Impostazioni"
Button1.Text = "AGGIORNA"
Button2.Text = "PULISCI"
btnZoomIn.Text = "INGRADISCI"
btnZoomOut.Text = "RIMPICIOLISCI"
btnMoveUp.Text = "SU"
btnMoveDown.Text = "GIÙ"
btnMoveLeft.Text = "SINISTRA"
btnMoveRight.Text = "DESTRA"
End If
End Sub
Private Sub btnZoomOut_Click(sender As Object, e As EventArgs) Handles btnZoomOut.Click
scaleFactor *= 1.5
zoom *= 1.25
Me.Invalidate()
End Sub
Private Sub btnZoomIn_Click(sender As Object, e As EventArgs) Handles btnZoomIn.Click
scaleFactor /= 1.5
zoom /= 1.25
Me.Invalidate()
End Sub
Private Sub btnMoveLeft_Click(sender As Object, e As EventArgs) Handles btnMoveLeft.Click
offsetX -= 50
offsetX -= 10.0 * zoom
Me.Invalidate()
End Sub
Private Sub btnMoveRight_Click(sender As Object, e As EventArgs) Handles btnMoveRight.Click
offsetX += 50
offsetX += 10.0 * zoom
Me.Invalidate()
End Sub
Private Sub btnMoveUp_Click(sender As Object, e As EventArgs) Handles btnMoveDown.Click
offsetY -= 10.0 * zoom
Me.Invalidate()
End Sub
Private Sub btnMoveDown_Click(sender As Object, e As EventArgs) Handles btnMoveUp.Click
offsetY += 10.0 * zoom
Me.Invalidate()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Invalidate()
TextBox1.Text = ""
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Normal
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
About.Show()
End Sub
Private Sub FastMenuToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FastMenuToolStripMenuItem.Click
FastMenu.Show()
End Sub
Private Sub NormalActualToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NormalActualToolStripMenuItem.Click
Me.Close()
Normal.Show()
End Sub
Private Sub ScientificToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ScientificToolStripMenuItem.Click
Me.Close()
Scientific.Show()
End Sub
Private Sub ProgrammerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ProgrammerToolStripMenuItem.Click
Me.Close()
Programmer.Show()
End Sub
Private Sub BinaryAdditionToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BinaryAdditionToolStripMenuItem.Click
Me.Close()
BinaryOp.Show()
End Sub
Private Sub SettingsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SettingsToolStripMenuItem.Click
Settingsc.Show()
End Sub
End Class