简体   繁体   中英

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 Windows 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.

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.

Simply put: with the Microsoft PropertyGrid, you can't change the color and font of a single property label or value text.

I think this is what you're asking.

PropertyGrid grid = new PropertyGrid();
grid.ForeColor = Color.Blue;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM