Results 1 to 8 of 8

Thread: Saving Colors [Resolved]

  1. #1

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195

    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.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    if you want the value in either Integer or RGB you can do these :
    VB Code:
    1. '///////// for the Integer version...
    2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.     Dim coltrans As Integer = ColorTranslator.ToWin32(TextBox1.BackColor)
    4.     Dim colorfile As IO.StreamWriter = New IO.StreamWriter(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
    5.     colorfile.WriteLine(coltrans)
    6.     colorfile.Close()
    7.  
    8. End Sub
    9.  
    10. '///////// for the RGB version ....
    11. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    12.     Dim coltrans As String = TextBox1.BackColor.R & TextBox1.BackColor.G & TextBox1.BackColor.B
    13.     Dim colorfile As IO.StreamWriter = New IO.StreamWriter(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
    14.     colorfile.WriteLine(coltrans)
    15.     colorfile.Close()
    16.  
    17. 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]

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Or serialize the color obj .

  5. #5

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Dynamic_sysop,

    Thats works great but how do I read the value from the file to apply it back to the object(textbox)?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Dim sr As New IO.StreamReader("c:\blah.txt")
    2.  
    3.         'This variable will hold color value , btw , you have more options for reading
    4.         'files . check them out .
    5.         Dim ColStr As String = sr.Read()

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    assuming you've saved as integer :
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim sReader As New IO.StreamReader(New IO.FileStream("D:\textboxcolor.txt", IO.FileMode.OpenOrCreate))
    3.         Dim col As ColorTranslator
    4.         TextBox1.BackColor = col.FromWin32(sReader.ReadLine)
    5.         sReader.Close()
    6.     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]

  8. #8

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    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
  •  



Click Here to Expand Forum to Full Width