There is one issue with this...
If the color of the Text is changed, the color of the DropDownButton also changes.
How can I change the color name TextColor but not change the DropDownButton TextColor?
Thanks,
Paulo
>You can use PrepareViewStyleInfo and try to set e.Style.TextColor to a contrasting color. Exactly how you get the contrasting color would be up to you. Below is a code snippet that uses a technique from our Windows Forms FAQ to get a contrasting color.
>
>Another simpler option would be to set e.Style.Text to the empty string in PrepareViewStyleInfo. This way all you would see is the colored cell and not the string.
>
>If you want to try to draw the text in some white rectangle, you could handle the CellDrawn event and do whatever drawing you want done there.
>
>
>private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
>{
> if(e.Style.CellType == "ColorEdit")
> {
> Color foreColor = Syncfusion.Drawing.ColorConvert.ColorFromString(e.Style.Text);// != null && e.Style.CellValue.ToString() != "") ? (Color) e.Style.CellValue : Color.Black;
> Color adjusted = Color.Black;
> AdjustForeColorBrightnessForBackColor(ref adjusted, foreColor, 1f);
> e.Style.TextColor = adjusted;
> }
>}
>public static void AdjustForeColorBrightnessForBackColor(ref Color foreColor, Color backColor, float prefContrastLevel)
>{
> float fBrightness = foreColor.GetBrightness();
> float bBrightness = backColor.GetBrightness();
> float curContrast = fBrightness - bBrightness;
> float delta = prefContrastLevel - (float)Math.Abs(curContrast);
> if((float)Math.Abs(curContrast) < prefContrastLevel)
> {
> if(bBrightness < 0.5f)
> {
> fBrightness = bBrightness + prefContrastLevel;
> if(fBrightness > 1.0f)
> fBrightness = 1.0f;
> }
> else
> {
> fBrightness = bBrightness - prefContrastLevel;
> if(fBrightness < 0.0f)
> fBrightness = 0.0f;
> }
> float newr, newg, newb;
> ConvertHSBToRGB(foreColor.GetHue(), foreColor.GetSaturation(), fBrightness, out newr, out newg, out newb);
> foreColor = Color.FromArgb(foreColor.A, (int)Math.Floor(newr * 255f),
> (int)Math.Floor(newg * 255f),
> (int)Math.Floor(newb * 255f));
> }
>}
>public static void ConvertHSBToRGB(float h, float s, float v, out float r, out float g, out float b)
>{
> if (s == 0f)
> {
> // if s = 0 then h is undefined
> r = v;
> g = v;
> b = v;
> }
> else
> {
> float hue = (float)h;
> if (h == 360.0f)
> {
> hue = 0.0f;
> }
> hue /= 60.0f;
> int i = (int)Math.Floor((double)hue);
> float f = hue - i;
> float p = v * (1.0f - s);
> float q = v * (1.0f - (s * f));
> float t = v * (1.0f - (s * (1 - f)));
> switch(i)
> {
> case 0: r = v; g = t; b = p; break;
> case 1: r = q; g = v; b = p; break;
> case 2: r = p; g = v; b = t; break;
> case 3: r = p; g = q; b = v; break;
> case 4: r = t; g = p; b = v; break;
> case 5: r = v; g = p; b = q; break;
> default: r = 0.0f; g = 0.0f; b = 0.0f; break; /*Trace.Assert(false);*/ // hue out of range
> }
> }
>}
>
>
>
>