PC Review


Reply
Thread Tools Rate Thread

CustomColors Property in ColorDialog control

 
 
Tony Lin
Guest
Posts: n/a
 
      8th Aug 2003
I am having trouble using the CustomColors property in the ColorDialog control.



I have created an int array from ARGB values and assigned it to the CustomColors property of my ColorDialog control. AllowFullOpen has been set to true.



Yet when I execute ShowDialog, the boxes specified for custom colors display only black.



Here's my code:



int[] customColors = new int[4];



customColors[0] = Color.Beige.ToArgb();

customColors[1] = Color.CadetBlue.ToArgb();

customColors[2] = Color.Chocolate.ToArgb();

customColors[3] = Color.DeepPink.ToArgb();



this.colorDialog.AllowFullOpen = true;

this.colorDialog.AnyColor = true;

this.colorDialog.CustomColors = customColors;



DialogResult dr = this.colorDialog.ShowDialog();







The ColorDialog displays 4 black squares and 12 white squares in the Custom Colors section.



What am I doing wrong here?



Tony Lin

Fremont, CA





 
Reply With Quote
 
 
 
 
Ying-Shen Yu
Guest
Posts: n/a
 
      8th Aug 2003
Hello Tony,
Because the .NET GDI+ uses the AARRGGBB color model, while the Windows
still uses the 00BBGGRR color model. Unfortunately, the property
CustomColors of ColorDialog didn't do this convertion internally, so you
must convert every argb value manuly. It's a known problem, I hope it will
be solved soon.

You may work around this by using the following static method

public static int ColorToColorref(Color clr)
{
return (clr.R + (clr.G << 8) + (clr.B << 16));
}

e.g.
customColors[0] = ColorToColorref(Color.Biege);

Be free to let me know if you have any questions on this issue, Thanks!


Kind regards,

Ying-Shen Yu [MSFT]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.

From: "Tony Lin" <(E-Mail Removed)>
Subject: CustomColors Property in ColorDialog control
Date: Thu, 7 Aug 2003 17:30:09 -0700
Newsgroups: microsoft.public.dotnet.framework.windowsforms

I am having trouble using the CustomColors property in the ColorDialog
control.

I have created an int array from ARGB values and assigned it to the
CustomColors property of

my ColorDialog control. AllowFullOpen has been set to true.

Yet when I execute ShowDialog, the boxes specified for custom colors
display only black.

Here's my code:

int[] customColors = new int[4];

customColors[0] = Color.Beige.ToArgb();
customColors[1] = Color.CadetBlue.ToArgb();
customColors[2] = Color.Chocolate.ToArgb();
customColors[3] = Color.DeepPink.ToArgb();

this.colorDialog.AllowFullOpen = true;
this.colorDialog.AnyColor = true;
this.colorDialog.CustomColors = customColors;

DialogResult dr = this.colorDialog.ShowDialog();

The ColorDialog displays 4 black squares and 12 white squares in the Custom
Colors section.

What am I doing wrong here?

Tony Lin
Fremont, CA

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exposing control property as list of items on property sheet... Charlie@CBFC Microsoft Dot NET Framework Forms 0 17th Nov 2006 05:31 PM
ColorDialog CustomColors Alpha value Marcus Kwok Microsoft Dot NET Framework Forms 0 27th Mar 2006 08:23 PM
can a custom control have an image property that can be set in design time from the property browser? news.austin.rr.com Microsoft Dot NET Compact Framework 3 3rd Mar 2005 02:08 AM
Adding code property to control property window NuBBeR Microsoft C# .NET 1 7th Oct 2004 05:15 PM
How to throw and catch an exception in the property set when property is bound to a wiform control Keith Roe Microsoft Dot NET Framework 2 4th Dec 2003 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 AM.