Torna al Thread
Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class Form1
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim blackPen As New Pen(Color.Red, 3)
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("coordinate.txt")
Dim line() As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = Split(sr.ReadLine(), ";", -1)
x1 = line(0)
y1 = line(1)
x2 = line(2)
y2 = line(3)
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
Loop Until line Is Nothing
sr.Close()
End Using
Catch ex As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
Me.Panel1.Refresh()
End Sub
Private Sub ApriFile(ByVal NomeFile As String)
Dim Testo As String
Dim FileReader As System.IO.StreamReader
Try
FileReader = New System.IO.StreamReader(NomeFile)
'Legge l'intero file e lo salva nella variabile "Testo".
Testo = FileReader.ReadToEnd
FileReader.Close()
cncCode.Text = Testo
Catch ex As System.IO.IOException
MsgBox("Si è verificato un errore durante la lettura dal file: " & ex.Message)
Finally
'Libera le risorse allocate con New.
FileReader = Nothing
End Try
End Sub
Private Sub mnuFileCommand(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuFileSalva.Click, mnuFileNuovo.Click, mnuFileEsci.Click, mnuFileApri.Click
Select Case CType(sender, MenuItem).Text
Case "&Nuovo"
Case "&Apri..."
If dlgApri.ShowDialog = DialogResult.OK Then
ApriFile(dlgApri.FileName)
End If
Case "&Salva..."
If dlgSalva.ShowDialog = DialogResult.OK Then
SalvaFile(dlgSalva.FileName)
End If
Case "&Esci"
Me.Close()
End Select
End Sub
Private Sub SalvaFile(ByVal NomeFile As String)
Dim FileWriter As System.IO.StreamWriter
Try
FileWriter = New System.IO.StreamWriter(NomeFile)
'Salva il contenuto di "txtTesto" nel file.
FileWriter.Write(cncCode.Text)
FileWriter.Close()
Catch ex As System.IO.IOException
MsgBox("Si è verificato un errore durante la scrittura sul file: " & ex.Message)
Finally
'Libera le risorse allocate con New.
FileWriter = Nothing
End Try
End Sub
End Class