473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Save checkbox settings on close

Hi

I have a program that sends an email to selected recipients.

I have two forms. One that creates and send the email and another that is used to select recipients and other information.

The program works great but everytime I close the program I lose all the settings for the recipients and other information.

The recipients are selected using checkboxes and other information for email is in text boxes.

Is there anyway to save these settings when the program is closed.
May 6 '07 #1
17 4496
Atran
319 100+
First put to your Form, FormClosing Event Handler, or FormClosed Event Handler, or not do that now, then Check this Code:

My.Settings.Save()

I hope this is helpful.
May 6 '07 #2
Hi Atran

I thought it was going to be that simple too.

I've tried including my.settings.save on form closing and also added my.settings.reload on form load but no joy.

Is there something else I have to do to make this setting work?
May 6 '07 #3
Can anyone please help me with this.

Having to redo the settings every time I close the form is driving me #^%$

Any help appreciated
May 9 '07 #4
Atran
319 100+
Hello Lazareth:
I will give you a simple idea.
example: I put in my Form Application a Textbox, then make The Textbox text to a notpad text in your windows.
Like if I have a notpad in my desktop, I can make the text of The Textbox take the notpad text, and when the Textbox text changed, that changing in the notpad...... (professionals use for this not notpad, they using DLL.....)

If you want the way, answer me to post the code.
Bye.
May 9 '07 #5
Atran
319 100+
Hello Lazareth:
I will give you a simple idea.
example: I put in my Form Application a Checkbox, and create a notpad in your directory. Make you Checkbox true value see the notpad text, that you can make the checkbox check the notpad text, if the notpad text was the text the checkbox want the checkbox must be true, if the notpad text wasnt the text the checkbox want the checkbox must be false....
Godbye...............
May 9 '07 #6
Atran
319 100+
If you want I can send you the code............................... Answer me.
May 9 '07 #7
Hi Atran,

That will be great if you can post the code as this is driving me nuts and anything that will overcome this I will appreciate.

Will I need a notepad doc for every checkbox and textbox as their is about 18 checkboxes and 4 text boxes.

I suppose once I see the code I'll know and not a major as I will be happy just to overcome this.

Thanks for your help
May 10 '07 #8
Atran
319 100+
Hi Atran,

That will be great if you can post the code as this is driving me nuts and anything that will overcome this I will appreciate.

Will I need a notepad doc for every checkbox and textbox as their is about 18 checkboxes and 4 text boxes.

I suppose once I see the code I'll know and not a major as I will be happy just to overcome this.

Thanks for your help
AS SOON, I will do!
May 10 '07 #9
TRScheel
638 Expert 512MB
Hi

I have a program that sends an email to selected recipients.

I have two forms. One that creates and send the email and another that is used to select recipients and other information.

The program works great but everytime I close the program I lose all the settings for the recipients and other information.

The recipients are selected using checkboxes and other information for email is in text boxes.

Is there anyway to save these settings when the program is closed.
XML or a database.

I would SUGGEST writing the change in information at the time it changes, although you could do it when the program closes, but if it closes erratically you could lose that information.

XML would be easiest.

Expand|Select|Wrap|Line Numbers
  1. Dim XMLDocument As System.Xml.XmlDocument = New System.Xml.XmlDocument()
  2.         Dim XMLParentElement As System.Xml.XmlElement = XMLDocument.CreateElement("CheckBoxes")
  3.         XMLDocument.AppendChild(XMLParentElement)
  4.  
  5.         'Foreach checkbox do this:
  6.         Dim XMLNode As System.Xml.XmlNode = XMLDocument.CreateNode(Xml.XmlNodeType.Element, Nothing, "TheCheckBox", Nothing)
  7.         Dim XMLAttribute As System.Xml.XmlAttribute = XMLDocument.CreateAttribute("Checked")
  8.         XMLAttribute.Value = "true"
  9.         XMLNode.Attributes.Append(XMLAttribute)
  10.         XMLParentElement.AppendChild(XMLNode)
  11.         'Till here, again, foreach check box
  12.  
  13.         Dim SWriter As System.IO.StreamWriter = New System.IO.StreamWriter("Mylocation.xml")
  14.         SWriter.Write(XMLDocument.InnerXml)
  15.         SWriter.Close()
There's the writing to the file, the reading is much the same, just backwards.

You would use a streamreader, and then readtoend, and pass that to XMLDocument.LoadXML
May 10 '07 #10
Atran
319 100+
Hi Atran,

That will be great if you can post the code as this is driving me nuts and anything that will overcome this I will appreciate.

Will I need a notepad doc for every checkbox and textbox as their is about 18 checkboxes and 4 text boxes.

I suppose once I see the code I'll know and not a major as I will be happy just to overcome this.

Thanks for your help
Hello Again. I find the code but it is hard to explain it here, I put the code under, but you can enter my email, and download the project from attachement panel files, [email removed]
[message removed]

Bye.
------------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Public Class Form1
  3.  
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.  
  6.  
  7.         'Let's Start form Here:
  8.         'Read carefully to understand the code, it is easy, but long.
  9.         'When you want to run this, open the Settings Savers Folder and Click the Button and see what is happen in the Folder.
  10.         'The problem is here some times you must click on button 3 or 4 times to do the action, do not think about this yet, first you need to understand the code.
  11.         'And The seconde problem is I put the files path here "/../../Settings Savers/", then the program contact this Folder when it is in "bin" Folder, if you want to fix that you must write in the files path "/Settings Savers/" but this will be error when you debug and run it from here, you must take the EXE Program and put it with the "Settings Savers" folder not inside the folder, with the folder.
  12.         ''''''''''''''''''''''''''''''''
  13.  
  14.         Try
  15.             If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt")) Then 'This mean "../../" in your project path, in "My Application/My Application/"
  16.                 CheckBox1.Checked = True
  17.             End If
  18.         Catch ex As Exception
  19.         End Try
  20.  
  21.         ''''''''''''''''''''''''''''''''
  22.  
  23.         Try
  24.             If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt").Equals(False)) Then
  25.                 CheckBox1.Checked = False
  26.             End If
  27.         Catch ex As Exception
  28.         End Try
  29.  
  30.         '''''''''''''''''''''''''''''''''
  31.  
  32.         Try
  33.             If (My.Computer.FileSystem.FileExists("../../Settings Savers/TextBox1.txt")) Then
  34.                 TextBox1.Text = "File Found: " + My.Computer.FileSystem.ReadAllText("../../Settings Savers/TextBox1.txt")
  35.             End If
  36.         Catch ex As Exception
  37.         End Try
  38.  
  39.         '''''''''''''''''''''''''''''''''
  40.  
  41.         Try
  42.             If (My.Computer.FileSystem.FileExists("../../Settings Savers/TextBox1.txt").Equals(False)) Then
  43.                 TextBox1.Text = "Not Found!"
  44.             End If
  45.         Catch ex As Exception
  46.         End Try
  47.  
  48.         '''''''''''''''''''''''''''''''''
  49.  
  50.     End Sub
  51.  
  52.     Private Sub SaveSettingsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveSettingsButton.Click
  53.  
  54.         Try
  55.  
  56.             If (CheckBox1.Checked = True) Then
  57.                 If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt")) Then
  58.                     MessageBox.Show("True Check was Arealy saved")
  59.                 End If
  60.  
  61.                 If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt").Equals(False)) Then
  62.                     System.IO.File.Create("../../Settings Savers/CheckBox1.txt")     'Create The CheckBox1.txt File
  63.                 End If
  64.             End If
  65.  
  66.             '''''''''''''''''''''''''''''''''
  67.  
  68.             If (CheckBox1.Checked = False) Then
  69.                 If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt")) Then
  70.                     My.Computer.FileSystem.DeleteFile("../../Settings Savers/CheckBox1.txt")
  71.                 End If
  72.  
  73.                 If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt").Equals(False)) Then
  74.                     MessageBox.Show("False Check was Saved!")
  75.                 End If
  76.             End If
  77.  
  78.         Catch ex As Exception
  79.             Return
  80.         End Try
  81.  
  82.     End Sub
  83.  
  84.     Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  85.  
  86.         Try
  87.  
  88.             Dim Message As String = "Save your settings?"
  89.             Dim Caption As String = "Attention!"
  90.             Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo
  91.             Dim Result As DialogResult
  92.             Result = MessageBox.Show(Message, Caption, Buttons)
  93.             If Result = DialogResult.Yes Then
  94.                 If (CheckBox1.Checked = True) Then
  95.                     If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt")) Then
  96.                         MessageBox.Show("True Check was Arealy saved")
  97.                     End If
  98.  
  99.                     If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt").Equals(False)) Then
  100.                         System.IO.File.Create("../../Settings Savers/CheckBox1.txt")     'Create The CheckBox1.txt File
  101.                     End If
  102.                 End If
  103.  
  104.                 '''''''''''''''''''''''''''''''''
  105.  
  106.                 If (CheckBox1.Checked = False) Then
  107.                     If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt")) Then
  108.                         My.Computer.FileSystem.DeleteFile("../../Settings Savers/CheckBox1.txt")
  109.                     End If
  110.  
  111.                     If (My.Computer.FileSystem.FileExists("../../Settings Savers/CheckBox1.txt").Equals(False)) Then
  112.                         MessageBox.Show("False Check was Saved!")
  113.                     End If
  114.                 End If
  115.             End If
  116.  
  117.         Catch ex As Exception
  118.  
  119.         End Try
  120.     End Sub
  121. End Class
May 11 '07 #11
Atran
319 100+
Check this site:
http://www.thescripts.com/forum/thread643188.html
May 11 '07 #12
Atran
319 100+
Hi Atran,

That will be great if you can post the code as this is driving me nuts and anything that will overcome this I will appreciate.

Will I need a notepad doc for every checkbox and textbox as their is about 18 checkboxes and 4 text boxes.

I suppose once I see the code I'll know and not a major as I will be happy just to overcome this.

Thanks for your help
Hello Again, Open this link to download the example, you will finish, and have the example, if any reason you cant download it till me.

Open this Link:

http://www.smokey-services.eu/forum/viewtopic.php?p=13731#13731


The file you will be download name is "Extract it before run it.zip"
Bye.
May 12 '07 #13
Hello Again, Open this link to download the example, you will finish, and have the example, if any reason you cant download it till me.

Open this Link:

http://www.smokey-services.eu/forum/viewtopic.php?p=13731#13731


The file you will be download name is "Extract it before run it.zip"
Bye.
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?
May 12 '07 #14
Atran
319 100+
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:
Expand|Select|Wrap|Line Numbers
  1. If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  2.      CheckBox1.Checked = True
  3. End If
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. If(My.Computer.FileSystem.FileExists("C:\test.txt").Equals(Flase)) Then
  2.      CheckBox1.Checked = Flase
  3. End If
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  2.      CheckBox1.Checked = True
  3. End If
  4.  
Then you can fix that by making Try Command:
Expand|Select|Wrap|Line Numbers
  1. Try
  2.  
  3.      If(My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  4.           CheckBox1.Checked = True
  5.      End If
  6.  
  7.      Catch ex As Exception
  8.  
  9. End Try
  10.  
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:
Expand|Select|Wrap|Line Numbers
  1. Try
  2.                     If (My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  3.                         MessageBox.Show("True Check was Arealy saved")
  4.                     End If
  5.  
  6.                     If (My.Computer.FileSystem.FileExists("C:\test.txt").Equals(False)) Then
  7.                         System.IO.File.Create("../../Settings Savers/CheckBox1.txt")
  8.                     End If
  9.                 End If
  10.  
  11.  
  12. If (CheckBox1.Checked = False) Then
  13.                     If (My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  14.                         My.Computer.FileSystem.DeleteFile("C:\test.txt")
  15.                     End If
  16.  
  17.                     If (My.Computer.FileSystem.FileExists("C:\test.txt").Equals(False)) Then
  18.                         MessageBox.Show("False Check was Saved!")
  19.                     End If
  20.                 End If
  21.  
  22.                 Catch ex As Exception
  23.  
  24. End Try
  25.  
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:
Expand|Select|Wrap|Line Numbers
  1. Dim Message As String = "Save your settings?"
  2. Dim Caption As String = "Attention!"
  3. Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo                     Dim Result As DialogResult
  4. Result = MessageBox.Show(Message, Caption, Buttons)
  5. If Result = DialogResult.Yes Then
  6.     'Put the Save Settings Code
  7. End If
  8.  
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.
May 12 '07 #15
Atran
319 100+
To Learn VB, Download Free Ebooks from this site:
http://www.getebooks4free.com/dot_net_free_ebooks.html
May 12 '07 #16
Atran
319 100+
Try Command:
In my 15th Post I write:
Expand|Select|Wrap|Line Numbers
  1.  Try
  2.  
  3.     If (My.Computer.FileSystem.FileExists("C:\test.txt")) Then
  4.                         CheckBox1.Checked = Flase
  5.     End If
  6.  
  7.    Catch ex As Exception
  8.  
  9. End Try
  10.  
If the test.txt file not found that will be error, then you can use Try to try.
May 12 '07 #17
Atran
319 100+
I forget to till to you how to create a text file, see this code:
Expand|Select|Wrap|Line Numbers
  1. System.IO.File.Create("C:\Hello.bmp")
  2.  
or Using this:
Expand|Select|Wrap|Line Numbers
  1. System.IO.File.CreateText("C:\Hello.txt")
  2.  
Hope this Tutorial was Helpful.
May 12 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sam Carleton | last post by:
It is my understanding that in .Net the registry is not the prefered place to save application settings. What has Microsoft put in place to replace it? I thought it was the .config file, but I...
7
by: seans | last post by:
Hi, I need to change the font, font size, and color of a button on a form. I need to save the current style settings and restore them later. Is there an easy way of doing that? Sorry if there...
10
by: Dica | last post by:
i've got an app that needs to connect to sql server and login with a useName/password. currently, my app saves this info in an XML file in plain text (i.e. no encryption). everytime the app is...
1
by: liuhengyi | last post by:
Hi, I have a test program that creates 5 threads and each thread uses XmlDocument.Save(filename) to save a Xml dom to a file. I have put the lock statement around the Save to prevent from...
0
by: liuhengyi | last post by:
Hi, I have a test program that creates 5 threads and each thread uses XmlDocument.Save(filename) to save a Xml dom to a file. I have put the lock statement around the Save to prevent concurrent...
0
by: #FPL# | last post by:
Anyone knows how to save (for ex. serialize) page settings from PageSetupDialog? I want to give users of my program possibility to save their prining settings. I've tried to set some of page...
8
by: Eric bouxirot | last post by:
hi there, i never used XML beforre, i prefere INI files, but i want do same things with XML file format.. before i can save/read some element of INI files without the need to parse or read...
5
by: solargovind | last post by:
Hi, In my Form, i have certain fields with Autonumber field(Transaction_id). While User Entering the data, the user close the form with only few data as they dont want to continue further for...
3
Atran
by: Atran | last post by:
I want to save my settings after I close my form. example: when I write in a textbox a word and I close the form and open it again see the word I was wrote it. example2: when my form runnig, I set...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.