Back to Devexpress

AppearanceObject.Font Property

windowsforms-devexpress-dot-utils-dot-appearanceobject-4cd5a89c.md

latest10.3 KB
Original Source

AppearanceObject.Font Property

Gets or sets the font used to paint the text.

Namespace : DevExpress.Utils

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[XtraSerializableProperty]
[DXCategory("Font")]
public virtual Font Font { get; set; }
vb
<XtraSerializableProperty>
<DXCategory("Font")>
Public Overridable Property Font As Font

Property Value

TypeDescription
Font

A Font object specifying the font used to display the contents of elements.

|

Remarks

The following example specifies custom fonts and font settings of a simple button and grid columns:

csharp
using System.Drawing;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            simpleButton1.Appearance.Font = new Font("Arial", 12, FontStyle.Bold);

            gridColumn1.AppearanceHeader.Font = new Font("Courier New", 14, FontStyle.Bold);
            gridColumn1.AppearanceCell.Font = new Font("Courier New", 10, FontStyle.Bold);

            gridColumn2.AppearanceHeader.Font = new Font("Times New Roman", 14, FontStyle.Underline);
            gridColumn2.AppearanceCell.Font = new Font("Times New Roman", 10, FontStyle.Underline);

            gridView1.OptionsView.ColumnHeaderAutoHeight = DevExpress.Utils.DefaultBoolean.True;
        }
    }
}
vb
Imports System.Drawing

Namespace DXApplication
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()
            simpleButton1.Appearance.Font = New Font("Arial", 12, FontStyle.Bold)

            gridColumn1.AppearanceHeader.Font = New Font("Courier New", 14, FontStyle.Bold)
            gridColumn1.AppearanceCell.Font = New Font("Courier New", 10, FontStyle.Bold)

            gridColumn2.AppearanceHeader.Font = New Font("Times New Roman", 14, FontStyle.Underline)
            gridColumn2.AppearanceCell.Font = New Font("Times New Roman", 10, FontStyle.Underline)

            gridView1.OptionsView.ColumnHeaderAutoHeight = DevExpress.Utils.DefaultBoolean.True
        End Sub
    End Class
End Namespace

Default Application Font

DevExpress WinForms controls use the “Tahoma” font as the default font. Use the following properties to change the default font used by DevExpress controls in your application:

Read the following topic for additional information: Default Application Font.

Appearance Settings Inheritance

Setting the Font property to the control’s default font (which is currently used by the user’s operating system) automatically sets the appearance object’s AppearanceOptions.UseFont property to false. If the UseFont property is set to false and the current Appearance object has a parent Appearance object, the Appearance object uses the parent’s font settings.

Use the AppearanceObject.GetFont method to obtain the font settings specified by the appearance object’s settings.

Read the following topics for additional information:

The following code snippets (auto-collected from DevExpress Examples) contain references to the Font property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-listbox-item-templates-enable-word-wrap/CS/S131055/Form1.cs#L45

csharp
e.Appearance.DrawBackground(e.Cache, e.Bounds);
TextUtils.DrawString(e.Graphics, control.GetItemText(e.Index), control.Appearance.Font,
    control.Appearance.ForeColor, e.Bounds);

xaf-win-custom-button-in-lookup-property-editor/CS/EFCore/LookUpButtonEF/LookUpButtonEF.Win/Editors/MyLookupPropertyEditor.cs#L18

csharp
AppearanceObject appearance = new AppearanceObject();
appearance.Font=new Font(FontFamily.GenericSansSerif, 10F, FontStyle.Underline);
((RepositoryItemLookupEdit)item).Buttons.Add(new EditorButton(ButtonPredefines.Glyph, "Edit", -1, true, true, true, HorzAlignment.Default, null, new KeyShortcut(System.Windows.Forms.Keys.Enter), appearance, "Press this button to edit the object"));

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/TreeList/TreeListItemControlProvider.cs#L49

csharp
e.DefaultDraw();
e.Cache.DrawString(validationError, e.Appearance.Font, e.Cache.GetSolidBrush(Color.Black), e.Bounds);
e.Handled = true;

winforms-calendar-dateedit-cell-appearance-customization/CS/Calendar_CellStyleProvider/Form1.cs#L67

csharp
if(font == null) {
    font = new Font(cell.Appearance.Font, System.Drawing.FontStyle.Bold);
}

winforms-grid-highlight-modified-cells/CS/Form1.cs#L35

csharp
e.Appearance.BackColor2 = Color.LimeGreen;
    e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
}

winforms-listbox-item-templates-enable-word-wrap/VB/S131055/Form1.vb#L44

vb
e.Appearance.DrawBackground(e.Cache, e.Bounds)
TextUtils.DrawString(e.Graphics, control.GetItemText(e.Index), control.Appearance.Font, control.Appearance.ForeColor, e.Bounds)
e.Handled = True

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/TreeList/TreeListItemControlProvider.vb#L55

vb
e.DefaultDraw()
e.Cache.DrawString(validationError, e.Appearance.Font, e.Cache.GetSolidBrush(Color.Black), e.Bounds)
e.Handled = True

winforms-calendar-dateedit-cell-appearance-customization/VB/Calendar_CellStyleProvider/Form1.vb#L82

vb
If font Is Nothing Then
    font = New Font(cell.Appearance.Font, FontStyle.Bold)
End If

winforms-grid-highlight-modified-cells/VB/Form1.vb#L37

vb
e.Appearance.BackColor2 = Color.LimeGreen
    e.Appearance.Font = New Font(e.Appearance.Font, FontStyle.Bold)
End If

winforms-custom-buttonedit-display-editvalue-on-button/VB/TestMyButtonEdit/MyButtonEditPainter.vb#L54

vb
Dim captionColor As Color = EditorsSkins.GetSkin(viewInfo.LookAndFeel.ActiveLookAndFeel)(EditorsSkins.SkinEditorButton).Color.GetForeColor()
info.Cache.DrawString(str_value, viewInfo.Appearance.Font, New SolidBrush(captionColor), info.Bounds, info.Appearance.GetStringFormat())
Return

See Also

UseFont

ParentAppearance

GetFont()

AppearanceObject Class

AppearanceObject Members

DevExpress.Utils Namespace