I want to use your ultraFontNameEditor but I need the list to limited to fixed-width or non-proportional fonts. Is this possible? For instance Courier is a fixed width font.
Hello Michael,
Two properties come to mind.
1. DropDownListWidth property can be used to set a fixed width on the items displayed in the editor's dropdown. 2. ShowFontNamesInFont allows you to toggle on or off the fonts that are shown for the text corresponding font. 3. If set to false you can then use the Font property to overrdie what font you wish to display. By default I believe the editor will display Courier for all the list items.
Here is an example of the properties:
private void Form1_Load(object sender, EventArgs e){ this.ultraFontNameEditor1.ShowFontNamesInFont = false; this.ultraFontNameEditor1.Font = new Font("Courier", 12); this.ultraFontNameEditor1.DropDownListWidth = 50;}
this.ultraFontNameEditor1.Font = new Font("Courier", 12);
this.ultraFontNameEditor1.DropDownListWidth = 50;}
Let me know if you have any additional questions.
I don't think I made myself clear enough. I don't want to change the font of the items displayed in the drop down list.
Currently the UltraFontNameEditor contains a list of every font available to the end user. I want to hide or remove the proportional fonts so the drop down list only contains non-proportional or fixed width fonts. Can this be done?
Hi Michael,
There's nothing built-in to the FontNameEditor to allow you to limit the list to particular fonts based on criteria. If you can identify the fonts you want, then you could handle the BeforeDropDown event, loop through the list, and remove any fonts that you don't want to display.
Another option would be to use another control, like UltraComboEditor and populate the list yourself. Getting the list of installed fonts isn't hard:
List<string> fontNameList = new List<string>( 50 ); System.Drawing.Text.InstalledFontCollection installedFonts = new System.Drawing.Text.InstalledFontCollection(); foreach( FontFamily ff in installedFonts.Families ) { fontNameList.Add( ff.Name ); } fontNameList.Sort();
Getting the installed fonts list is easy creating the drop down to look and feel like the UltraFontNameEditor is not. I will try and remove them in the BeforeDropDown event.
UltraFontNameEditor is basically a derived UltraComboEditor. The big difference is that it populates the list for you. Also, it shows the font using that font. So you could easily set the Font on each item as you add it to the UltraCombo. Of course, there is a little more to it than that. It also accounts for non-text fonts like Wingdings and displays a readable name. But I don't know if that matters in this case, since you are limiting your list to fixed-width fonts, anyway, and you probably don't want any image fonts like that.