Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:46:25+00:00 2026-05-28T04:46:25+00:00

When I place a TRibbon control on a form that is not the MainForm

  • 0

When I place a TRibbon control on a form that is not the MainForm of the application, that TRibbon’s actions (i.e. Cut, Paste) will always return focus to the MainForm after the action is executed.

This occurs even if the TForm that holds the TRibbon is not a child of the MainForm.

I am using Windows 7 64-bit, Embarcadero RAD Studio XE Version 15.0.3953.35171.

Am I using the TRibbon control incorrectly, or is this an issue with the TRibbon?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:46:26+00:00Added an answer on May 28, 2026 at 4:46 am

    This is evidently by design. Sample code snippet from ‘ribbonactnctrls.pas’:

    procedure TRibbonBaseButtonControl.Click;
    begin
      inherited;
      SetFocus(Application.MainForm.Handle);
    end;
    

    As you see there are no conditions checked that would help us avoid the call. There’s the same code also in menu item selection and key press handlers.

    I would probably modify the source commenting the focus calls, and try to see if there’re any side effects.

    As an alternative you can restore the focus back to your form after it is switched to the main form. Suppose ‘ActionList1’ is the TActionList that contains standard actions on the not main form:

    type
      TForm2 = class(TForm)
        ..
        procedure ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
      private
       ..
    
    procedure TForm2.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
    begin
      PostMessage(Handle, WM_SETFOCUS, WPARAM(True), 0);
    end;
    

    This will however cause the main form to flash briefly every time an action is executed. If you don’t want that, you can change the design so that the main form knows when it is getting an unwanted focus, and fake that it’s not focused.

    In unit1:

    const
      UM_CANCELIGNOREFOCUS = WM_USER + 7;
    
    type
      TForm1 = class(TForm)
        ..
      private
        FIgnoreFocus: Boolean;
        procedure UMCancelIgnoreFocus(var Msg: TMessage); message UM_CANCELIGNOREFOCUS;
        procedure WMNCActivate(var Msg: TWMNCActivate); message WM_NCACTIVATE;
      public
        property IgnoreFocus: Boolean write FIgnoreFocus;
      end;
    
    ...
    uses Unit2;
    
    procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
    begin
      Msg.Result := 0;
      if not (Msg.Active and FIgnoreFocus) then
        inherited;
    end;
    
    procedure TForm1.UMCancelIgnoreFocus(var Msg: TMessage);
    begin
      FIgnoreFocus := False;
      TForm(Msg.WParam).SetFocus;
    end;
    

    in unit2:

    uses
      unit1;
    
    procedure TForm2.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
    begin
      Form1.IgnoreFocus := True;
      PostMessage(Form1.Handle, UM_CANCELIGNOREFOCUS, NativeInt(Self), 0);
    end;
    

    However, this is not enough if you don’t have ‘MainFormOnTaskBar’ set in project source, since then the main form will not only gain focus but will be brought to front. In this case both forms could respond to the unwanted focus change/activation by freezing their z-orders. The code would then become for unit1:

    const
      UM_CANCELIGNOREFOCUS = WM_USER + 7;
    
    type
      TForm1 = class(TForm)
        ..
      private
        FIgnoreFocus: Boolean;
        procedure UMCancelIgnoreFocus(var Msg: TMessage); message UM_CANCELIGNOREFOCUS;
        procedure WMNCActivate(var Msg: TWMNCActivate); message WM_NCACTIVATE;
        procedure WMWindowPosChanging(var Msg: TWMWindowPosChanging);
            message WM_WINDOWPOSCHANGING;
      public
        property IgnoreFocus: Boolean read FIgnoreFocus write FIgnoreFocus;
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Unit2;
    
    procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
    begin
      Msg.Result := 0;
      if not (Msg.Active and FIgnoreFocus) then
        inherited;
    end;
    
    procedure TForm1.WMWindowPosChanging(var Msg: TWMWindowPosChanging);
    begin
      inherited;
      if FIgnoreFocus then
        Msg.WindowPos.flags := Msg.WindowPos.flags or SWP_NOZORDER;
    end;
    
    procedure TForm1.UMCancelIgnoreFocus(var Msg: TMessage);
    begin
      FIgnoreFocus := False;
      TForm(Msg.WParam).SetFocus;
    end;
    

    and for unit2:

    type
      TForm2 = class(TForm)
        ..
        procedure ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
      private
        procedure WMWindowPosChanging(var Msg: TWMWindowPosChanging);
            message WM_WINDOWPOSCHANGING;
      public
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    uses
      unit1;
    
    {$R *.dfm}
    
    procedure TForm2.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
    begin
      Form1.IgnoreFocus := True;
      PostMessage(Form1.Handle, UM_CANCELIGNOREFOCUS, NativeInt(Self), 0);
    end;
    
    procedure TForm2.WMWindowPosChanging(var Msg: TWMWindowPosChanging);
    begin
      inherited;
      if Form1.IgnoreFocus then
        Msg.WindowPos.flags := Msg.WindowPos.flags or SWP_NOZORDER;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where is a good place to start with making an application in .NET that
i place 4 textfields in my application. I need that 4 textfields allows only
When I place a control on a tabpage in Silverlight the control is placed
I want to place a Webpart on a page that holds a subfolder of
The place where I work at has this function that inserts an object information
Where should I place .h and .lib files so that I can just write
How to place a pushpin in middle of the MapView so that we can
I work in a place that has gazillions of tools which require tons of
Place a single button on a page that could be used as an ON/OFF
unless (place =~ /^\./) == 0 I know the unless is like if not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.