Filtering Font Options in a PropertyGrid

Anonymous
2021-04-05T15:18:19.867+00:00

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.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,302 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,579 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 48,826 Reputation points
    2021-04-05T15:41:55.203+00:00

    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.

    0 comments No comments