How set ForeColor in PropertyGrid?
-
Thursday, February 21, 2008 11:02 AM
How can I set color for text in cells of PropertyGrid for diverses properties, which have only get-method and any which have both (get and set) methods?????
Now use I ViewForeColor. But set one color for both types of properties.
Thanks
Kasavchenko Yuriy
All Replies
-
Wednesday, February 27, 2008 7:59 AM
Hi geokas,
As far as I know, the forecolor for a specified cell in the PropertyGrid cannot be set respectively, at least not easy to do so, by using a tool like Reflector, you can see how the PropertyGrid paints the values for each property item:
(The following code is in System.Windows.Forms.PropertyGridInternal.GridEntry class)[code snappet from Reflector]
public virtual void PaintValue(object val, Graphics g, Rectangle rect,
Rectangle clipRect, PaintValueFlags paintFlags)
{
.......
string lastValueString;
PropertyGridView gridEntryHost = this.GridEntryHost;
int valuePaintIndent = 0;
Color textColor = gridEntryHost.GetTextColor();
if (this.ShouldRenderReadOnly)
{
textColor = this.GridEntryHost.GrayTextColor;
}
........
if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None)
{
backgroundBrush = SystemBrushes.Highlight;
textColor = SystemColors.HighlightText;
}
.....
}
public Color GetTextColor()
{
return this.ForeColor;
}
[/code snappet from Reflector]
As you can see, the GridEntry class use the PropertyGrid.ForeColor to paint normal entries, gray color for the read-only entries, and highlight color for the current selected entry. It's by design and no easy to change.
Best Regards,
Zhi-xin Ye.


