C# Properties: Font and Color Change on the Fly
Does anyone know how to change the font and the font color of the property value I am inputting? I am using Windo开发者_运维百科ws Forms and Propertygrid. Thank you.
I am thinking of using:
using( Font myFont = new Font("Arial", 8, FontStyle.Italic) )
but am not sure how to implement this, and I am not sure how to change the color of the text.
Simply put: with the Microsoft PropertyGrid, you can't change the color and font of a single property label or value text.
Are you trying to change the font and forecolor of the PropertyGrid control itself, or trying to change the values of two properties you've defined in the PropertyGrid? If you created a separate class and set it as the SelectedObject, then it should be as simple as editing the class. Getting the Most Out of the .NET Framework PropertyGrid Control
If you have a class that is populating the PropertyGrid, you could just use the constructor in the class or the DefaultValueAttribute tag to setup all your default values prior to attaching it to the PropertyGrid. Or create an instance of the class, change just those public properties you want for that instance, and then attach it.
I think this is what you're asking.
PropertyGrid grid = new PropertyGrid();
grid.ForeColor = Color.Blue;
精彩评论