|
-
Jun 3rd, 2009, 04:54 PM
#1
Thread Starter
Lively Member
[RESOLVED] Save Settings using button?
I want it so that when i click button2, all the settings like, font color for example, will be save to a .ini or .xml(which ever one is better). What do i need to do for this ? Thanks!
-
Jun 3rd, 2009, 04:56 PM
#2
Re: Save Settings using button?
You could use My.settings to store all of this information. In your button click event, just type in
-
Jun 3rd, 2009, 05:03 PM
#3
Thread Starter
Lively Member
Re: Save Settings using button?
-
Jun 3rd, 2009, 05:05 PM
#4
Re: Save Settings using button?
 Originally Posted by x DeaDLy
It didn't work =\
Remember the comment on your other thread about thinking?
What do you want to save? formlesstree has shown you how you can save your settings - its up to you to decide which settings to save and what you want to call them.
If you want to know more about my.settings try reading the documentation or googling. Here's an article : http://www.devsource.com/c/a/Languag...tion-Settings/
-
Jun 3rd, 2009, 05:06 PM
#5
Re: Save Settings using button?
"It didn't work =\" - unfortunately that doesn't tell us anything.
1) what code did you try?
2) Did you get an error?
3) If so, what was the error?
4) If NOT, then what happened that shouldn't have happened? What didn't happen that should have?
5) Post any and all relevant code.
-tg
-
Jun 3rd, 2009, 05:09 PM
#6
Re: Save Settings using button?
You can use PropertyBindings which take no code.
In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)".
Then click "(PropertyBindings") and once it's highlighted click the "..." button that appears. Then go through the list of properties and when you find one you want to save, click it once to highlight it, then from the drop down box click New and create a name for the setting. Then click OK and your program will save it and load it for you.
-
Jun 3rd, 2009, 05:19 PM
#7
Thread Starter
Lively Member
Re: Save Settings using button?
Sorry guys, idk y im acting like this today. Ok what I am trying to do is save the forecolor change of label1. here is my entire project code:
Code:
Public Class Form1
Dim instance As ColorDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDialog As New ColorDialog
MyDialog.Color = Label2.ForeColor
MyDialog.Color = Label1.ForeColor
MyDialog.Color = CheckBox1.ForeColor
If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Label2.ForeColor = MyDialog.Color
Label1.ForeColor = MyDialog.Color
CheckBox1.ForeColor = MyDialog.Color
End If
End Sub
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
End Sub
End Class
I tried what you told me to do Vectris but the, Forecolor change of the label won't save. Like the default color is black, i change it to red, hit the "Save" button. close the form and open it back up, but the change of forecolor of the label did not get saved. my friend used a .ini file to save his color change in delphi. Thanks hope this clears things out. Again i apologize for my behavior
-
Jun 3rd, 2009, 05:23 PM
#8
Re: Save Settings using button?
You shouldn't have any Save button, just follow the instructions I gave you and as long as you close form without Pressing the Stop button on the debug it will save.
-
Jun 3rd, 2009, 05:43 PM
#9
Thread Starter
Lively Member
Re: Save Settings using button?
"In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)"." Click what button once? and I just want to know how to save the changes using an .ini file. Thanks for you help
-
Jun 3rd, 2009, 05:54 PM
#10
Thread Starter
Lively Member
Re: Save Settings using button?
Ok i found out how to create a .ini file using the code:
Code:
Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
objWriter = New StreamWriter(App_Path() & "\test.ini")
objWriter.WriteLine(Label1.ForeColor)
objWriter.WriteLine(Label2.ForeColor)
objWriter.Close()
End Sub
but wen i save it, it saves it shows up in the .ini file when i open it, but it does not load my configuration, like i set the label1.forecolor to red using colordialog. how wud i load the .ini file? Thanks
-
Jun 3rd, 2009, 05:57 PM
#11
Fanatic Member
Re: Save Settings using button?
StreamReader?
-
Jun 3rd, 2009, 06:05 PM
#12
Thread Starter
Lively Member
Re: Save Settings using button?
 Originally Posted by BillBoeBaggins
StreamReader? 
Can you give me a code to set it up please? Thanks
-
Jun 3rd, 2009, 06:12 PM
#13
Fanatic Member
Re: Save Settings using button?
I am willing to bet it is almost exactly the reverse of what your doing now.
Reverse your assignments. Change an object from a Writer to a Reader.
You'll appreciate it more if you figure it out on your own.
-
Jun 3rd, 2009, 06:21 PM
#14
Thread Starter
Lively Member
Re: Save Settings using button?
ok i made the streamreader but don't know how to make it read my "test.ini" for the forecolor. Here is what i typed for the StreamWriter:
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
objWriter = New StreamWriter(App_Path() & "\test.ini")
objWriter.WriteLine("[Color]")
objWriter.Write(ColorDialog1.Color)
objWriter.Close()
MsgBox("Saved!")
End Sub
and here is the StreamReader code:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objReader = New StreamReader(App_Path() & "\test.ini")
objReader.Read()
End Sub
also, do i put the streamreader in the Form1_load? Thanks!
-
Jun 3rd, 2009, 06:26 PM
#15
Fanatic Member
Re: Save Settings using button?
For your StreamReader piece.
1. You will need to use the ReadLine() method
2. You will need to loop through the file using I believe the Peek method (Testing for End of File)
3. You will need to assign the values "Read" and load them into the associated properties in the correct order as they were written.
I forget the firiing order of events so I am not sure if Form_Load is best as I am not sure if the Objects even exist at this point.
-
Jun 3rd, 2009, 06:39 PM
#16
Thread Starter
Lively Member
Re: Save Settings using button?
Im tryin will know if i succeed
-
Jun 3rd, 2009, 06:45 PM
#17
Thread Starter
Lively Member
Re: Save Settings using button?
Did not succeed, here is the code for streamwriter and reader:
Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
objWriter = New StreamWriter(App_Path() & "\test.ini")
objWriter.WriteLine("[Color]")
objWriter.Write(Label1.ForeColor)
objWriter.Close()
MsgBox("Saved!")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim EntireFile As String
objReader = New StreamReader(App_Path() & "\test.ini")
EntireFile = objReader.ReadToEnd()
objReader.Close()
End Sub
-
Jun 3rd, 2009, 06:59 PM
#18
Fanatic Member
Re: Save Settings using button?
I have nothing to test this code on.
I am sure people could think of better ways of storing/pulling the data out/in but that is my sample, and that demonstrates what you need.
vb Code:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
objWriter = New StreamWriter(App_Path() & "\test.ini")
objWriter.WriteLine("[Color]" & label1.ForeColor )
objWriter.Close()
MsgBox("Saved!")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim EntireFile As String
Dim OneLine As String
objReader = New StreamReader(App_Path() & "\test.ini")
OneLine = objReader.ReadLine()
objReader.Close()
End Sub
Label1.ForeColor=Right(OneLine,Len(OneLine)-7)
-
Jun 3rd, 2009, 07:10 PM
#19
Re: Save Settings using button?
 Originally Posted by x DeaDLy
"In Design View, click your button once, then open the Properties Panel and click the + at the top to expand "(ApplicationSettings)"." Click what button once? and I just want to know how to save the changes using an .ini file. Thanks for you help
What button? What's the button that your trying to save the color of? That's the button.
-
Jun 3rd, 2009, 07:14 PM
#20
Thread Starter
Lively Member
Re: Save Settings using button?
Thanks man oh ya where do i put the
Label1.ForeColor=Right(OneLine,Len(OneLine)-7) ?
and it gives me an Error where it says "Right" on that same line, i will try to figure it out though
-
Jun 3rd, 2009, 07:15 PM
#21
Thread Starter
Lively Member
Re: Save Settings using button?
 Originally Posted by Vectris
What button? What's the button that your trying to save the color of? That's the button.
Sorry, found out what you were talking about, thx for being patient =]
-
Jun 3rd, 2009, 07:32 PM
#22
Fanatic Member
Re: Save Settings using button?
gives me an Error where it says "Right" on that same line, i will try to figure it out though
It is probably not a VB.Net supported function so you would need to find an equivalent.
where do i put the
Label1.ForeColor=Right(OneLine,Len(OneLine)-7) ?
Anywhere after you retrieve the value. You could dump it into a variable and then use it later if you wanted.
-
Jun 3rd, 2009, 07:45 PM
#23
Re: Save Settings using button?
 Originally Posted by x DeaDLy
Sorry, found out what you were talking about, thx for being patient =]
Well now that you know try it out. If you do it right you can skip all this coding stuff .
-
Jun 3rd, 2009, 07:59 PM
#24
Thread Starter
Lively Member
Re: Save Settings using button?
LoL ya i did ahaha thx much man!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|