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!
Printable View
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!
You could use My.settings to store all of this information. In your button click event, just type in
vb Code:
My.settings.save
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/
"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
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.
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:
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 behaviorCode: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
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.
"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
Ok i found out how to create a .ini file using the code:
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? ThanksCode: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
StreamReader? :)
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.
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:
and here is the StreamReader code: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
also, do i put the streamreader in the Form1_load? Thanks!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
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.
Im tryin will know if i succeed
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
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)
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
It is probably not a VB.Net supported function so you would need to find an equivalent.Quote:
gives me an Error where it says "Right" on that same line, i will try to figure it out though
Anywhere after you retrieve the value. You could dump it into a variable and then use it later if you wanted.Quote:
where do i put the
Label1.ForeColor=Right(OneLine,Len(OneLine)-7) ?
LoL ya i did ahaha thx much man!