question

BrettOssman-3361 avatar image
0 Votes"
BrettOssman-3361 asked BrettOssman-3361 commented

Filtering Font Options in a PropertyGrid

I have a Font option in my PropertyGrid wher the user can set the font.

Is there a way to filter fonts for selection?

For example, say I don't want the user to be able to pick an Arial or Sans Serif font.

I am using the standard PropertyGrid (System.Windows.Forms.PropetyGrid), for this settings window:

84849-image.png

I simply included a property based on Drawing.Font to the object:

  <Category("Display"), Description("The font of the text displayed in the grid.")>
  Public Property Font() As Drawing.Font Implements IGridSetting.Font
      Get
          Return FontConverter.FromBase64(_font)
      End Get
      Set(ByVal value As Drawing.Font)
          _font = FontConverter.ToBase64(value)
          OnPropertyChanged("Font")
      End Set
  End Property

that I add to the PropertyGrid through SelectedObject.

  Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
      MyBase.OnLoad(e)
      Me.PropertyEditor.SelectedObject = <object>
  End Sub

This causes the above PropertyGrid to include the standard Font settings for that object.
However, I have yet to find a way to filter the Font Names that are offered in that PropetyGrid.

This approach may well not be as customizable as I like, but want to check before I look into creating a totally custom PropertyGrid.


dotnet-csharpdotnet-visual-basic
image.png (11.3 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@BrettOssman-3361
I'm afraid not.
The window that the user sees when selecting Font in the PropertyGrid is FontDialog, and we can't seem to make any changes to it.
My idea is to detect the current font in Control.FontChanged Event. If it is Arial or Sans Serif font, a prompt will pop up to tell the user that it cannot be used, and then set the font to the previous one.

0 Votes 0 ·

Thanks for the response.

Yeah, I was also hoping to avoid the error messages, and just not offer the font in the first place.

0 Votes 0 ·

@BrettOssman-3361
I think the standard PropetyGrid may not be able to do it. Have you considered customizing PropetyGrid and FontDialog?

0 Votes 0 ·
Show more comments

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

I assume that when you say you allow the user to set the font that means you are displaying a list of fonts via a combo box cell. In that case you are responsible for getting the values (fonts) to populate the drop down with. You should filter the font list before binding it to the control.

If you aren't doing it this way then please provide information on how you are binding the font selection in the grid.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.