简体   繁体   English

C# 属性:即时更改字体和颜色

[英]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.我正在使用 Windows Forms 和 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.我正在考虑使用: using( Font myFont = new Font("Arial", 8, FontStyle.Italic) )但不知道如何实现,也不知道如何更改文本的颜色。

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?您是要更改 PropertyGrid 控件本身的字体和前景色,还是要更改您在 PropertyGrid 中定义的两个属性的值? If you created a separate class and set it as the SelectedObject, then it should be as simple as editing the class.如果您创建了一个单独的 class 并将其设置为 SelectedObject,那么它应该像编辑 class 一样简单。 Getting the Most Out of the .NET Framework PropertyGrid Control充分利用 .NET 框架 PropertyGrid 控件

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.如果您有一个正在填充 PropertyGrid 的 class,您可以只使用 class 或 DefaultValueAttribute 标记中的构造函数来设置所有默认值,然后再将其附加到 PropertyGrid。 Or create an instance of the class, change just those public properties you want for that instance, and then attach it.或者创建一个 class 的实例,只更改该实例所需的那些公共属性,然后附加它。

Simply put: with the Microsoft PropertyGrid, you can't change the color and font of a single property label or value text.简单地说:使用 Microsoft PropertyGrid,您无法更改单个属性 label 或值文本的颜色和字体。

I think this is what you're asking.我想这就是你要问的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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