How to save panel/form

Hi anyone has any sample code in saving and reading from a panel/form? or anyone has any idea how to retrieve all the codes input into the panel/form and creating it into a file, and reading frm it later on? i read the part on lecture 15 and tried some methods but doesn't seem to work.. below are my codes for the saving function and opening function.. enlightenment needed pls!

--------------------------------saving---------------------------------
Private Sub File_SaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_SaveAs.Click
Dim fileChooser As SaveFileDialog = New SaveFileDialog
Dim result As DialogResult = fileChooser.ShowDialog()
Dim fileName As String
Dim binForm As New BinaryFormatter

fileChooser.CheckFileExists = False



If result = DialogResult.Cancel Then
Return
End If

fileName = fileChooser.FileName

If (fileName = "" OrElse fileName = Nothing) Then
MessageBox.Show("Invalid File Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Try
output = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)
Dim byteText() As Byte = System.Text.Encoding.ASCII.GetBytes(drawWindow.Text)
output.Write(byteText, 0, byteText.Length)
output.Close()


Catch fileException As FileNotFoundException
MessageBox.Show("File does not exits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)


End Try
End If
End Sub

-----------------------------opening-----------------------------------

Private Sub open_bttn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles open_bttn.Click
Dim fileChooser As OpenFileDialog = New OpenFileDialog
Dim result As DialogResult = fileChooser.ShowDialog()
Dim fileName As String
Dim HDcreate As New HD_Create(Me)

If result = DialogResult.Cancel Then
Return
End If

fileName = fileChooser.FileName

If (fileName = "" OrElse fileName = Nothing) Then

MessageBox.Show("Invalid FileName", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
input = New FileStream(fileName, FileMode.Open, FileAccess.ReadWrite)
' create an array of bytes of the size of file
' and read file contents to it.
Dim byteText(input.Length) As Byte
input.Read(byteText, 0, byteText.Length)
' convert bytes array to string and display in the text box
HDcreate.Show()
Me.Hide()
HDcreate.drawWindow.Text = System.Text.Encoding.ASCII.GetString(byteText)
' close the file stream so that other streams may use it
input.Close()


End If

End Sub
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories