Back to Devexpress

How to: Modify Captions of Navigation Buttons

windowsforms-4229-controls-and-libraries-scheduler-examples-appearance-how-to-modify-captions-of-navigation-buttons.md

latest3.7 KB
Original Source

How to: Modify Captions of Navigation Buttons

  • Feb 07, 2019
  • 2 minutes to read

Note

This article is relevant for versions prior to v2008 vol.2. More recent versions contains the SchedulerNavigationButtonOptions class. Use the following properties: SchedulerNavigationButtonOptions.NextCaption - specifies a text for the Next navigation button; SchedulerNavigationButtonOptions.PrevCaption - specifies a text for the Previous navigation button.

If appointments are not called appointments in your application, then you definitely need to change the caption for navigation buttons. How would you go about doing this?

The answer is simple - localize. All .NET DevExpress controls provide a Localizer class for this purpose.

You should create a DevExpress.XtraScheduler.Localization.SchedulerLocalizer class descendant and override its Localizer.GetLocalizedString property. Then, assign an instance of your class to the SchedulerLocalizer’s static Localizer.Active property. For more information on localizing controls, refer to Localization topic.

The following code snippet illustrates this technique applied to a button’s caption text.

csharp
using DevExpress.XtraScheduler.Localization;
//...
public partial class Form1 : Form
{
    public Form1()
    {
        SchedulerLocalizer.Active = new MyLocalizer();
        InitializeComponent();
    }
    public class MyLocalizer : SchedulerLocalizer 
    {
        public override string GetLocalizedString(SchedulerStringId id)
        {
            switch (id)
            {
                case SchedulerStringId.Caption_PrevAppointment:
                    return "Previous Item";
                case SchedulerStringId.Caption_NextAppointment:
                    return "Next Item";
            }
            return base.GetLocalizedString(id);
        }
    }
vb
Imports DevExpress.XtraScheduler.Localization
'...
Public Partial Class Form1
    Inherits Form
    Public Sub New()
        SchedulerLocalizer.Active = New MyLocalizer()
        InitializeComponent()
    End Sub
    Public Class MyLocalizer
        Inherits SchedulerLocalizer
        Public Overrides Function GetLocalizedString(ByVal id As SchedulerStringId) As String
            Select Case id
                Case SchedulerStringId.Caption_PrevAppointment
                    Return "Previous Item"
                Case SchedulerStringId.Caption_NextAppointment
                    Return "Next Item"
            End Select
            Return MyBase.GetLocalizedString(id)
        End Function
    End Class

Note

Handle the SchedulerControl.CustomDrawNavigationButton event, to paint navigation buttons manually.

See Also

Localization

CustomDrawNavigationButton

DrawDefault()

SchedulerNavigationButtonOptions