Re: Saving Colors to a db
Dean Cleaver <[email protected]> Wed, 18 Jul 2007 07:42:55 +1200
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <4543A775711185429E59B18055D41674231A90@sxslakl004.xceptionsoftware.com> |
I went and looked up the class too - wish I had known about it 6 years ago when I started writing this project - but now, because I've used my method, the risk of changing it and breaking the current system is too great. :( Dino -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Peter Osucha Sent: Wednesday, 18 July 2007 07:01 To: [email protected] Subject: Re: [DOTNET-WINFORMS] Saving Colors to a db Actually, to preserve system colors as well as web colors, use ToOle() and FromOle() instead of ToWin32() and FromWin32(). peter -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Peter Osucha Sent: Tuesday, July 17, 2007 2:52 PM To: [email protected] Subject: Re: [DOTNET-WINFORMS] Saving Colors to a db Russ, I didn't notice your post until after I had reviewed what Dino suggested. And fortunately, yes, the ColorTranslator object works perfectly. So there is absolutely not additional code needed. When I save to the db, I use the ColorTranslator.ToWin32() method and when I retrieve from the db, I use the ColorTranslator.FromWin32() method. Color names - if they exist - are preserved perfectly. Thanks for the tip Peter -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Russ Alan Sent: Wednesday, July 04, 2007 5:31 PM To: [email protected] Subject: Re: [DOTNET-WINFORMS] Saving Colors to a db Have you looked at ColorTranslator? Russ -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Dean Cleaver Sent: Tuesday, July 03, 2007 1:32 PM To: [email protected] Subject: Re: [DOTNET-WINFORMS] Saving Colors to a db Peter, I've been doing this for about 6 years, so I'm confident I have the code that works - somewhere. Let me did around for you - but basically, the essential bits are to check the incoming string for Color.KnownColor - i.e. is it "White" or "Red" etc. If that's not the case, check if it's 6 or 8 characters - ARGB hex or RGB hex - it changed at one point I think. I'll post the sample code once I get a chance to look right through the layers and see what I do with colour properties. Dino -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Peter Osucha Sent: Tuesday, 3 July 2007 07:35 To: [email protected] Subject: [DOTNET-WINFORMS] Saving Colors to a db Hi, I am saving Color values to a database as integers after converting the color using the ToArgb() method. When I retrieve the color, I am resetting it using the FromArgb() method. However, this doesn't preserve the color name if the color has a name - as shown in this simple test proc. private void Button3_Click ( object sender, EventArgs e ) { Color col1 = Color.DarkBlue; int col1int = col1.ToArgb ( ); Color col2 = Color.FromArgb ( col1int ); Console.WriteLine ( "{0}, {1}", col1, col2 ); } If I desire to save and retrieve Colors to a database and to preserve the color name if it exists, I imagine I need to save a string of the name instead of the argb value? Peter