3

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.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
Zeos6
  • 273
  • 1
  • 7
  • 18

3 Answers3

1

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.

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
  • I want to change the font and the color of one property's value dynamically in the grid, not the entire grid. I am using get and set for the properties. – Zeos6 Jul 12 '11 at 18:31
  • Somehow it seems that it should be easy but I can't see how to do it. – Zeos6 Jul 12 '11 at 18:37
  • Yeh the proof of concept is in this article http://msdn.microsoft.com/en-us/library/aa302334.aspx#vsnetpropbrow_topic04 – Odnxe Jul 12 '11 at 19:04
  • Had a look. Thank you. Maybe something can be done by overriding OnPaint, but a lot of work. – Zeos6 Jul 12 '11 at 19:10
1

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

Nicolas Cadilhac
  • 4,680
  • 5
  • 41
  • 62
-1

I think this is what you're asking.

PropertyGrid grid = new PropertyGrid();
grid.ForeColor = Color.Blue;
Odnxe
  • 644
  • 1
  • 6
  • 19
  • I believe this changes the fore color for the entire grid. I simply want to change the text color for one property value. For example, if you input a negative value for amount, I want it to be red and if the value is positive I want it to be black. – Zeos6 Jul 12 '11 at 18:26
  • You want the property in the property grid to reflect the changes in color or the Control in which its referencing? – Odnxe Jul 12 '11 at 18:34
  • I want the property not the control to change color. However, at this point I would settle for the control changing color or for both the value and the single control changing color. – Zeos6 Jul 12 '11 at 18:39
  • I can give you the code to reflect the changes on the control you are manipulating but I can't give you the code(b/c it will take to long lol) for changing the property itself but refer to my comment in bemused's answer. – Odnxe Jul 12 '11 at 19:05
  • I am not sure what you are saying Odnxe. I already have the code to change the property values. I am tryin gto change the font and the color. Alternatively, I'd like to change the background color of the one property I am changing. That too seems like a lot of pain. – Zeos6 Jul 12 '11 at 19:12