Default Application Font
- 4 minutes to read
By default, DevExpress Windows Forms controls use the Tahoma font (as specified by the static WindowsFormsSettings.FontBehavior property) of the default system font size. You can change the default font used by the controls with the following static properties.
- WindowsFormsSettings.DefaultFont - Gets or sets the default font for DevExpress controls (except menus and toolbars). This is a static property.
- WindowsFormsSettings.DefaultMenuFont - Gets and sets the default font used to display text on menus, toolbars and popup menus (except Ribbon elements). This is a static property.
- WindowsFormsSettings.DefaultPrintFont - Gets or sets the default text font for printing. This is a static property.
We highly recommend that you use the DevExpress Project Settings dialog to change the default font for DevExpress controls.
If you need to change the default font in code, do that prior to running the main application form (see the sample below). Once a default font is set, do not change it when the application is running.
using DevExpress.XtraEditors;
[STAThread]
static void Main() {
WindowsFormsSettings.LoadApplicationSettings();
WindowsFormsSettings.DefaultFont = new System.Drawing.Font("Arial", 12);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Compared to DevExpress controls, standard Windows Forms controls use a different default font. The WindowsFormsSettings.FontBehavior property introduces several modes that help you force the DevExpress and standard controls to use the same font. Other FontBehavior
modes allow you to apply one of the system fonts to DevExpress controls.
The DefaultFont
and FontBehavior
property values can be specified in a configuration file beforehand and then loaded at runtime using the WindowsFormsSettings.LoadApplicationSettings method. See this topic to learn more.
Fonts of Individual Controls
If you’d like to only change a certain control’s font, use the AppearanceObject.Font setting provided by the control’s appearance property (typically, appearance properties have the “Appearance” sub-string in their names). Make a note that some controls consist of multiple visual elements. These controls expose multiple appearance properties for all their elements. If this is the case, the font settings need to be changed across all the appearance properties provided by the control.
For instance, the following code shows how to change the font of all visual elements of a GridControl’s GridView, which consist of multiple elements.
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
void SetGridFont(GridView view, Font font) {
foreach(AppearanceObject ap in view.Appearance)
ap.Font = font;
}
// Usage:
SetGridFont(gridView1, new Font("Courier New", 10));
The AppearanceObject objects also provide two special properties to adjust a control’s font.
- AppearanceObject.FontSizeDelta - Gets or sets an integer value by which the font size is adjusted.
- AppearanceObject.FontStyleDelta - Gets or sets an additional style to be applied to the font.
Fonts of XtraBars Elements (Menus, Bars, Ribbon UI and Dock Panels)
As mentioned above, the default font of DevExpress menus, toolbars and popup menus can be customized using the static WindowsFormsSettings.DefaultMenuFont property. The default font of Ribbon items and dock panels is specified by the WindowsFormsSettings.DefaultFont property.
A more flexible alternative to specifying the default font of XtraBars Elements is using bar and dock controllers:
- DefaultBarAndDockingController or BarAndDockingController.Default - The default bar and dock controller, which allows you to specify the appearance of XtraBars Elements throughout your application.
- BarAndDockingController - Allows you to specify the appearance of XtraBars Elements within a single form. The BarAndDockingController, when used, takes priority over the default bar and dock controller settings.
Bar and dock controllers expose the following appearance and font customization properties:
- BarAndDockingController.AppearancesBar - Specifies appearance settings for items in bars and menus in different states.
- BarAndDockingController.AppearancesRibbon - Provides the default appearance settings of the Ribbon Controls and Ribbon Forms.
- BarAndDockingController.AppearancesBackstageView - Provides the default appearance settings applied to BackstageViewControl controls.
- BarAndDockingController.AppearancesDocking - Provides the default appearance settings for all dock panels, implemented with the DockManager component.
The following code changes the default font of main menus throughout the application using the default bar and dock controller.
DevExpress.XtraBars.BarAndDockingController.Default.AppearancesBar.MainMenu.Font = new Font("Tahoma", 14);
The Appearance… properties of bar and dock controllers take priority over the static WindowsFormsSettings.DefaultMenuFont and WindowsFormsSettings.DefaultFont properties.
Read the following topic to learn more: Look and Feel.