|
-
Aug 1st, 2003, 02:04 PM
#1
Thread Starter
Addicted Member
Saving Colors [Resolved]
How do I save the backcolor of a textbox to file?
Ive looked everywhere I could, but didn't find anything that worked for me!
Any help much appreciated!
Last edited by Hole-In-One; Aug 1st, 2003 at 07:01 PM.
-
Aug 1st, 2003, 02:27 PM
#2
To what kind of file? You could let .NET handle it all for you by using the DynamicProperties bit at designtime. Otherwise I'd suggest writing either the RGB values or the name if you are using NamedColors then use the Parse or New methods to recreate the color from said values.
-
Aug 1st, 2003, 02:35 PM
#3
if you want the value in either Integer or RGB you can do these :
VB Code:
'///////// for the Integer version...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim coltrans As Integer = ColorTranslator.ToWin32(TextBox1.BackColor)
Dim colorfile As IO.StreamWriter = New IO.StreamWriter(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
colorfile.WriteLine(coltrans)
colorfile.Close()
End Sub
'///////// for the RGB version ....
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim coltrans As String = TextBox1.BackColor.R & TextBox1.BackColor.G & TextBox1.BackColor.B
Dim colorfile As IO.StreamWriter = New IO.StreamWriter(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
colorfile.WriteLine(coltrans)
colorfile.Close()
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Aug 1st, 2003, 02:42 PM
#4
Sleep mode
Or serialize the color obj .
-
Aug 1st, 2003, 05:24 PM
#5
Thread Starter
Addicted Member
Dynamic_sysop,
Thats works great but how do I read the value from the file to apply it back to the object(textbox)?
-
Aug 1st, 2003, 06:30 PM
#6
Sleep mode
VB Code:
Dim sr As New IO.StreamReader("c:\blah.txt")
'This variable will hold color value , btw , you have more options for reading
'files . check them out .
Dim ColStr As String = sr.Read()
-
Aug 1st, 2003, 06:41 PM
#7
assuming you've saved as integer :
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sReader As New IO.StreamReader(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
Dim col As ColorTranslator
TextBox1.BackColor = col.FromWin32(sReader.ReadLine)
sReader.Close()
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Aug 1st, 2003, 07:00 PM
#8
Thread Starter
Addicted Member
Thanks it works great!
It sooo easy after you see the code!
Makes ya think I should've figured that one out!
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
|