Tutorial, Step by Step.
Hi Atran,
Thanks for all your help.
There is no download available at this link.
Do I need to register to this site before I can see it?
Hi Lazareth,in That web site, I set the file, but after I see the web site says the file was failed. I have no way to send the project.
If the code was take time you do not read it. Then see this code below if you understand this, you will know to build that all:
-------------------------------------------------
FileExists means File Found or !!!
start the code:
-
If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
-
CheckBox1.Checked = True
-
End If
-
This code is checking the file "test.txt" if the file is in the "C:\"
If the file found, the checkbox will be true.
--------------------------------------------------
start this code:
-
If(My.Computer.FileSystem.FileExists("C:\test.txt").Equals(Flase)) Then
-
CheckBox1.Checked = Flase
-
End If
-
This code is checking the file "test.txt" if the file is not in the "C:\" because we write ".Equals(Flase)", the checkbox will be False.
---------------------------------------------------
If the File wasnt, this code will be shown error:
-
If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
-
CheckBox1.Checked = True
-
End If
-
Then you can fix that by making Try Command:
-
Try
-
-
If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
-
CheckBox1.Checked = True
-
End If
-
-
Catch ex As Exception
-
-
End Try
-
Try command will Try, if the code was not found it way, it continue, it just try.
---------------------------------------------------
You see the path we add is "C:\test.txt" how you can to add it with the directory of your program debuged, you can write this "/test.txt", in visual project folders, the program will debuged in "/bin/Debug/MyProgram.exe" you can put "test.txt" there to read MyProgram.exe from test.txt.
---------------------------------------------------
To make to your Form a Closing Event Handler, you can do it by design mode, in the form properties panel, click on the Actions icon, then choose an event and write in the event textbox (giving a name) Form_MyEvent, Like: Form_Load, Form_Closing, Form_Closed, Form_MouseMove.........
---------------------------------------------------
Then see the "System.IO" what does has.
example: System.IO.File.Delete("C:\DeleteThisNow.doc") 'Delete a File
example2: System.IO.File.Create("C:\NewFile.exe") 'Create New File
---------------------------------------------------
Lets Save your settings by this code.
Now add to your form a button, by double clicking on the button, visual will create a Click event to your button.
then make to the button this action code:
-
Try
-
If (My.Computer.FileSystem.FileExists("C:\test.txt")) Then
-
MessageBox.Show("True Check was Arealy saved")
-
End If
-
-
If (My.Computer.FileSystem.FileExists("C:\test.txt").Equals(False)) Then
-
System.IO.File.Create("../../Settings Savers/CheckBox1.txt")
-
End If
-
End If
-
-
-
If (CheckBox1.Checked = False) Then
-
If (My.Computer.FileSystem.FileExists("C:\test.txt")) Then
-
My.Computer.FileSystem.DeleteFile("C:\test.txt")
-
End If
-
-
If (My.Computer.FileSystem.FileExists("C:\test.txt").Equals(False)) Then
-
MessageBox.Show("False Check was Saved!")
-
End If
-
End If
-
-
Catch ex As Exception
-
-
End Try
-
But the problem is sometimes you may Click on the Button 4 or 5 times to do this action.
---------------------------------------------------
Lets create a messagebox shown when you closing the form.
after you make to the form the closing handler, put(copy)this code inside the handle.
lets start:
-
Dim Message As String = "Save your settings?"
-
Dim Caption As String = "Attention!"
-
Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo Dim Result As DialogResult
-
Result = MessageBox.Show(Message, Caption, Buttons)
-
If Result = DialogResult.Yes Then
-
'Put the Save Settings Code
-
End If
-
Here we say, when you close the form, then will shown a messagebox with two buttons (Yes, No) if you choose Yes button,
Yes button will do the action up mean this action code:
If Result = DialogResult.Yes Then 'you see DialogResult.Yes, you can put No
'Put the Save Settings Code
End If
---------------------------------------------------
We finish, NOTHING IS HARD JUST TAKE TIME.
Good Luck.