Skip to main content

Ribbon Form

  • 4 minutes to read

Ribbon control (TdxRibbon) and Ribbon status bar (TdxRibbonStatusBar) are only a part of the window’s non-client area.

The Microsoft® Office® 2007 UI guidelines contain requirements that developers must follow when implementing different portions of the non-client area when using a Ribbon. As such, you must develop numerous routines that paint the form’s elements with the visual appearance and dimensions specified by the Ribbon UI guidelines.

As you can imagine, the TdxRibbonForm class takes care of these requirements. To benefit from this full-featured form:

  • Add the dxRibbonForm unit to the ‘uses’ clause.

  • Derive your form from TdxRibbonForm. For the Office 2019, Office 2016, Office 2016 Tablet, or Office 2013 style Ribbon, we recommend that you disable Windows Aero effects for the form. To accomplish this, handle the form’s OnCreate event and add the “DisableAero := True;” line to the event handler.

  • Drop TdxRibbon and TdxRibbonStatusBar (if needed) components onto the form and configure them as required.

  • Activate the Ribbon’s SupportNonClientDrawing option.

The following image shows a form painted using a standard style (the Ribbon’s SupportNonClientDrawing property is False) and a Ribbon style (the Ribbon’s SupportNonClientDrawing property is True).

For a quick start with Ribbon application and Ribbon form development, use the IDE templates shipped with the ExpressBars Suite. To learn more, refer to the Ribbon Application and Form IDE Templates topic.

Additional Tips

In a Ribbon style, it is possible to display scrollbars within an MDI parent Ribbon form, if the TdxRibbonForm.DisableMDIClientScrollBars property is False. If displayed, the scrollbars are painted using the Windows theme.

In addition to the provided capabilities, the TdxRibbonForm class also allows you to customize the height of the Ribbon Form’s title bar. To do this, override the TdxRibbonForm.GetCaptionHeightDelta method. To learn how to accomplish this task, refer to the How to Change the Height of the Ribbon Form’s Title in Code help topic.

At runtime, if the Ribbon control‘s SupportNonClientDrawing property is set to True, part of the Ribbon displays a Ribbon Form’s non-client area. By default, a Ribbon Form is automatically adjusted at runtime to retain the control layout specified at design time. As a result, the form is vertically resized to preserve control offsets relative to the Ribbon’s and form’s bottom edges. Use the form’s AdjustLayoutForNonClientDrawing property to customize this behavior.

To allow a Ribbon control to correctly paint a Ribbon Form’s non-client area on itself (the Ribbon control’s SupportNonClientDrawing property is set to True), do the following:

  • Set the Ribbon Form’s RibbonAlwaysOnTop property to True to ensure that a Ribbon control is always the topmost control on the form. Note that this property is available only in Delphi/C++Builder 2006 or later.

  • If you handle the Ribbon Form’s OnShow event, make certain that you call the Windows API’s PostMessage function to postpone the execution of the code that moves focus or affect form painting in your event handler.

The following example demonstrates how to handle the Ribbon Form’s OnShow event to display a modal dialog when this form is shown.

uses
  ..., dxRibbonForm;
// ...
const
  CM_POSTPONEDFORMSHOW = WM_USER + 2;
// ...
type
  TForm1 = class(TdxRibbonForm)
// ...
    procedure FormShow(Sender: TObject);
    procedure CMPostponedFormShow(var Message: TMessage); message CM_POSTPONEDFORMSHOW;
// ...
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
// ...
procedure TForm1.FormShow(Sender: TObject);
begin
  PostMessage(TForm(Sender).Handle,CM_POSTPONEDFORMSHOW,0,0);
end;
procedure TForm1.CMPostponedFormShow(var Message: TMessage);
begin
  inherited;
  if Showing then
  try
    ShowMessage('Test');
  except
    Application.HandleException(Self);
  end;
end;

Note

To prevent potential painting problems in MDI applications with Ribbon controls, take the following steps:

  • Inherit your MDI forms from TdxRibbonForm.

  • In RAD Studio 2007 or later, disable an MDI application’s MainFormOnTaskbar option, which is enabled by default in the application’s project source file.

See Also