|
-
Jan 31st, 2003, 05:51 AM
#1
Thread Starter
Hyperactive Member
Saving object values in a textfile.
How do I save objects values in a textfile? Particularly the backcolour of an object? This is what I have:
VB Code:
Function SaveFile()
FileOpen(1, Application.StartupPath & "config.ini", OpenMode.Output)
PrintLine(1, TreeView1.BackColor)
FileClose(1)
End Function
But it's throwing an exception:
-------------------------------------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll
Additional information: File I/O with type 'Color' is not valid.
-----------------------------------------------------------------------
Any help on how to save objects values in a textfile?
Thanks.
-
Jan 31st, 2003, 09:54 AM
#2
write the .Name property of the color, and then when you load it again, use the Color.FromName(string sName) function. This assumes that you're using named colors.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jan 31st, 2003, 11:05 AM
#3
I would also recommend that you use an xml config file instead of the old school ini files. That is the direction everything is going especially with .net.
-
Jan 31st, 2003, 01:05 PM
#4
Thread Starter
Hyperactive Member
..use the Color.FromName(string sName) function.
I'm not quite sure how to do this (the on-line help is usless!). I have this:
VB Code:
TreeView1.BackColor.Name = Color.FromName(sTemp)
but I guess this isn't right as it's giving me a blue squiggle Any help would be appreciated.
..I would also recommend that you use an xml config file instead of the old school ini files.
I'm unfamiliar with xml at the moment, but eventually...
-
Jan 31st, 2003, 02:37 PM
#5
Thread Starter
Hyperactive Member
Anybody help
-
Jan 31st, 2003, 03:07 PM
#6
Whats the value of sTemp?
Actually I see the trouble you are trying to set the name but Color.FromName gets a color object based on the name so it is not a string value its a color value. Try this:
Treeview1.BackColor = Color.FromName(sTemp)
-
Jan 31st, 2003, 04:20 PM
#7
Thread Starter
Hyperactive Member
The value of sTemp is ffc0ffff and I did as you suggested Edneeis, but I get:
----------------------------------------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: This control does not support transparent background colors.
----------------------------------------------------------------------
As far as i'm aware, i'm not setting any transpaernt background colours!
Here's the two functions i'm using for loading and saving:
VB Code:
Function LoadFile()
Dim sTemp As String
FileOpen(1, Application.StartupPath & "\config.ini", OpenMode.Input)
sTemp = LineInput(1)
TreeView1.BackColor = Color.FromName(sTemp)
FileClose(1)
End Function
Function SaveFile()
FileOpen(1, Application.StartupPath & "\config.ini", OpenMode.Output)
PrintLine(1, TreeView1.BackColor.Name)
PrintLine(1, TreeView1.ForeColor.Name)
FileClose(1)
End Function
and the config.ini file only holds the value ffc0ffff
-
Jan 31st, 2003, 04:34 PM
#8
It should be used like this:
TreeView1.BackColor.Name = Color.FromName("Red")
-
Jan 31st, 2003, 04:49 PM
#9
Also check out the ColorTranslator class if you need to do some form of conversion between color formats. It has OLE, Win32, and HTML.
-
Jan 31st, 2003, 05:36 PM
#10
Thread Starter
Hyperactive Member
Originally posted by Edneeis
It should be used like this:
TreeView1.BackColor.Name = Color.FromName("Red")
I understand what you mean Edneeis, but the weird thing is that this:
VB Code:
PrintLine(1, TreeView1.BackColor.Name)
gives me a number like this: ff008040
While this:
VB Code:
PrintLine(1, TreeView1.[i]Fore[/i]Color.Name)
gives me an actual colour name - white
-
Jan 31st, 2003, 05:47 PM
#11
Thread Starter
Hyperactive Member
Right, it seems that some colours in a ColorDialog() return names while some return numbers.
Is there any way to specify only named colours from a ColorDialog() without having a list of them to pick from?
-
Jan 31st, 2003, 05:55 PM
#12
Is it a greenish color?
try this:
VB Code:
TreeView1.BackColor=ColorTranslator.FromHtml("#ff008040")
-
Jan 31st, 2003, 06:04 PM
#13
Yeah that should do it just Try..Catch it and in the catch add a "#" to the front and try it again.
VB Code:
Try
treeview1.BackColor = Color.FromName(sTemp)
Catch
treeview1.BackColor = ColorTranslator.FromHtml("#" & sTemp)
End Try
-
Jan 31st, 2003, 06:08 PM
#14
Thread Starter
Hyperactive Member
-
Jan 31st, 2003, 06:16 PM
#15
Originally posted by Edneeis
Yeah that should do it just Try..Catch it and in the catch add a "#" to the front and try it again.
VB Code:
Try
treeview1.BackColor = Color.FromName(sTemp)
Catch
treeview1.BackColor = ColorTranslator.FromHtml("#" & sTemp)
End Try
Did we cross posts because this should cover both names and numbers?
-
Jan 31st, 2003, 06:22 PM
#16
Thread Starter
Hyperactive Member
I think we did! Another frustration eased by the mighty Edneeis!
-
Jan 31st, 2003, 06:38 PM
#17
Well I don't know about mighty but I'm glad I could help.
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
|