VisualHint's blog

A new logo for VisualHint

I’m happy to unveil the new VisualHint identity. It is based on the old logo but now features a brand new look that I find far more attractive, dynamic and professional. It precedes the conception of a new web site that will bring together the existing library for MFC and the new one for .Net.

VisualHint logo


Visual Studio 2005 released

I downloaded a copy of the express edition yesterday and I am happy that the Smart PropertyGrid library compiles well. First tests show no crashes also. I encourage you to continue your beta testing under the official release.


DateTimePicker, PropertyGrid and BackColor wedding

The Microsoft PropertyGrid doesn’t use the DateTimePicker control to edit a date. It uses a simple dropped down month calendar and therefore it is not even possible to edit a time only. This was the indication of a challenge for me.

If you do a search with the keywords "DateTime BackColor" on the web and on the newsgroups you will find a lot of posts asking how to change the BackColor of a DateTimePicker control as well as answers saying that it is not so obvious and that you could try this way and this way. Nothing clear. Since I had not a lot of bugs to fix in the last days, I decided to add the DateTimePicker control as a feel for the first release of SPG. And after several days of pain and despair, I finally got it working and integrated in the PropertyGrid. Here it is: PropertyGrid and DateTime

PropertyGrid and DateTime

There was several difficulties. The first one was to show the proper BackColor. Once done, I discovered that when made initially visible, there was a nasty flickering effect. So I had to fix that to get the same quality standard as all the other inplace controls. I did it but the fix was producing erratic drawing when clicking on the fieds of the control or using the arrow keys to change the values. Well, now this is done and I am pretty proud of it.

You can see it in action in the new build 11 and the updated sample application.


How to manage the appearance of a default value

The Microsoft PropertyGrid has a built-in mechanism to handle default values: it displays them by using a non-bold font while the other properties are painted with the bold style. The Visual Studio designer also proposes a menu to reset a property to its default value.

I could have done the same in SPG but this would not be very flexible. Some people, like I did in a C++ application recently, will want for example to display a very subtle different background for non default values. Or maybe you simply want no difference at all. That's why I provide no built-in mechanism at all !!

Therefore I had to show you how simple this is to do it externally. Here is an example that will simply mimic the Microsoft way (the code is placed in a derived class of PropertyGrid):

protected void CheckDefaultValue(PropertyEnumerator propEnum)
  if (propEnum.Property.Value == null)

  DefaultValueAttribute attr = (DefaultValueAttribute)propEnum.

  if ((attr != null) &&
      propEnum.Property.Value.Font = this.Font;
    propEnum.Property.Value.Font = new Font(propEnum.Property.
      Value.Font, FontStyle.Bold);

// Check the property value against the default value and set the
// font accordingly
protected override void OnPropertyChanged
  (VisualHint.SmartPropertyGrid.PropertyChangedEventArgs e)

// Set the correct font on the property when it is initially created
protected override void OnPropertyCreated(PropertyCreatedEventArgs e)

Download a sample application

I have published today a sample application. In fact this is my test program that showcases almost every feature of the PropertyGrid. At the same time, I have updated the SmartPropertyGrid assembly to build 2 since a dozen of bugs have been fixed.

Download it now

Smart PropertyGrid in action


Multiple values in a row

Here is the third post of the set I promised previously:

To store multiple variables in a single property is a new concept brought by SPG. I wanted to do it when a customer who bought the MFC version asked me if it was possible to have in one row a double value and its associated unit. Although it was feasible with some work it was not instantaneous, and even if this customer achieved to do it I decided to implement a built-in mechanism in the .NET version. And finally this is done. Here is a screenshot from my test app:

alt text

It will be demonstrated in the first demo to come.

So, what else can you do with that ? Your imagination is the limit here, but let's see another example. The font dialog is able to let the user choose a color for a font. But the font doesn't store the color. That's why the Microsoft PropertyGrid doesn't manage colors for fonts. SPG can allow you to store in one row a reference to a font and to a color. By writing the right Look class, it can be displayed the way you want (a color box followed by the font text or a colored font text, ...), and it will be edited by a font dialog that enables color selection.

Of course this is not limited to two variables. If you have some built-in arrangements of multiple variables that you would like to see developed in the package, just tell me.



I’m still here and very active. Because several people asked me the status of the library by mail, here are the very uninteresting reasons of my silence: first some family came here then I took some vacations and very recently I had a major computer crash with data loss. I only got it back from repair some days ago. When everything is restored, I will finalize the evaluation of an obfuscator.


Properties auto-discovery

Here is the second post of the set I promised previously:

The strength of SPG is that you can really work with it at run-time. You will be able to add, remove, move and delete properties with very few lines of code. The appearance and the way to edit these properties can also be changed easily. But to be complete, the existing way of showing properties in the grid has still to be available. Right now, this is done with the SelectedObject Property. It means, among other things, that all the great techniques brought to you on CodeProject by fellow developers still apply to SPG. Here are two of them:

Concerning these two articles, I would like to thank their authors because they helped me, among other sources of documentation, to understand the inner workings of this complex windows forms control. And I'm pretty sure that if I read them again, I will find a small detail that I missed.

But I digress... I used the reflection to find all the custom properties and populate the control. Sticking to the old way is good, but why not to bring a more convenient ease to it. I take the example of a pen. By default, the Pen class publishes a lot of its properties, and some of them are not very useful when you develop a graphical application. "CompoundArray", "Transform", "Brush" only show their class name as value, so why not remove them ? This code will do it:

[PropertyHide("CompoundArray", "Transform", "Brush")]

After removing some properties, it can be beneficial to change the way that some of the remaining ones are displayed and edited. If you have developed your own custom color picker, you would like to assign it to the "Color" property. And maybe you prefer to show updown arrows for editing the pen width. It can be done like this:

[PropertyFeel(new string[] {
"Width", VisualHint.SmartPropertyGrid.PropertyGrid.FeelEditUpDown,
"Color", VisualHint.SmartPropertyGrid.PropertyGrid.FeelList })]

As you can see, all attributes of this kind will take the name of an auto-discovered property as a first parameter. In the example above, pairs of parameters are passed in an array so that it is possible to change the Feel class of many properties. A picture being better than thousands words, here is one:

PropertyGrid customizations PropertyGrid customizations


Short term plans

Sorry not to have posted during several days. Things continue to progress though. The main thing is that I have frozen the development because I am now working heavily on the documentation for the API. NDOC does not fully recognize C# 2.0 but nevertheless I can work with it and preview my progress. Once I am satisfied with it, I will publish an alpha release so that you can play with the PropertyGrid. From the discussion that will result, I will continue the development and create a beta program.

In the meatime, please continue to give me your thoughts and expectations.


Visual C# Express beta2

Just installed it yesterday and everything seems fine with the current code. I had only one compile error and it deals with MaskedTextBox.InputText. This property simply disappeared and this is a real annoyance for me. I currently have a workaround. Let me explain my concern:

In a previous post, I showed an example with a phone number. It is stored as a string variable that doesn't contain the characters of the mask, i.e. 5551234567 and not (555)123-4567. When the user edits the variable I want to retrieve a string without the special characters and InputText was allowing that. My workaround is to temporarily reset the mask to nothing, grab the string and restore the mask, and even freeze the painting during this operation. Please, Microsoft, restore this property, or let me know how elegantly I can do that ;)