TMainmenu: Hide but shortcuts allowed lazarus / 31-LCL ---------------------------------------------------------------------- Milsa · 2023-07-09 16:48 I have TMainMenu in my project. Sometimes I need to run my application in fullscreen withtou main menu on the top of screen. This is code for menu show: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if FullScreen.Running then      begin        if Menu = Nil then          Menu := MainMenu        else          Menu := Nil;      end; When I remove menu then I am without shortcuts from menu. It is posible use shortcuts from menu with hidden main menu without duplicity in code? I think shortcuts in main menu and shortcuts routines in FormKeyDown with hidden main menu? Maybe it is possible change main menu's height to 0 and then it is done. ---------------------------------------------------------------------- Pe3s · 2023-07-09 16:58 Hello, hide menu Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Self.Menu := nil; show menu Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  self.Menu := MainMenu1; ---------------------------------------------------------------------- Milsa · 2023-07-09 17:09 This is my code upper. I need code for hide menu but all menu shortcuts must be allowed. Removing menu from menu property disallows menu shortcuts. It is possible to change menu height to 0 without remove menu? ---------------------------------------------------------------------- Milsa · 2023-07-09 17:14 This is my exact code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormMain.SwitchFullscreen(b: Boolean);begin  with FullScreen do  begin    if Running = b then      Exit;    if not Running then    begin      WLeft := Left;      WTop := Top;      WWidth := Width;    WHeight := Height;      Menu := Nil;    end;    Running := b;    ToolBar.Visible := not Running;    StatusBar.Visible := not Running;  if Running then    begin      BorderStyle := bsNone;      WindowState := wsFullScreen;    end    else    begin      BorderStyle := bsSizeable;      WindowState := wsNormal;    end;    if not Running then    begin      Menu := MainMenu;      Left := WLeft;      Top := WTop;      Width := WWidth;      Height := WHeight;    end;  end;  {  FormResize(Self);  }  OpenGLControl.Free;  OpenGLControl := TOpenGLControl.Create(PanelScreen);  with OpenGLControl do  begin    OnPaint := @OpenGLControlPaint;    Parent := PanelScreen;  end;  fTex := 0;  FormResize(OpenGLControl);end;                    Shortcut does not work in fullscreen. They can not. ---------------------------------------------------------------------- jamie · 2023-07-09 21:56 I don't know your target and I don't think there is any cross platform way to do this unless the IntLCL supports the LM_SysKeyDown message ?  I see that you are using a Panel so I can assume that is a TPanel which can receive keyboard input. You can create a local morph class for the TPanel to support the WM_SysKeyDown message and process the AL+??? messages.  You would need to create a CASE list of those that also live in your menu.  I tested by sending that message to the Form and it does allow passage and is processable. Not all messages are passed through the class. ---------------------------------------------------------------------- jamie · 2023-07-09 23:30 Here is an example of a local class fixup to capture the message. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses Windows,Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls; type TButton = Class(StdCtrls.TButton)   Procedure WMSysKeyDown(Var Msg:Tmessage) Message WM_SysKeyDown; end;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    MainMenu1: TMainMenu;    MenuItem1: TMenuItem;  procedure MenuItem1Click(Sender: TObject);  private  public  end; var  Form1: TForm1; implementation {$R *.lfm}Procedure TButton.WmSysKeyDown(Var Msg:TMessage);Begin   Inherited;   Msg.Result:= 1;   Caption := Msg.wParam.Tostring;End;{ TForm1 } procedure TForm1.MenuItem1Click(Sender: TObject);begin  Application.Terminate;end; end.   if you play with that, you will see the ALT key code until you press another and from that point on, only the other keys shows.  You can mimic the accelerator keys by doing a ALT+? Actually, you can use this exclusively if you wish. The Panel I believe receives the Input if the flags are set or use a Tbutton for the whole surface ---------------------------------------------------------------------- Milsa · 2023-07-10 15:11 I think that duplicity is easier: 1. Enabled menu: Shorcuts in main menu. 2. Disabled menu: Shortcuts in FormKeyDown with case and testing disabled menu. But thank you for your time. ---------------------------------------------------------------------- wp · 2023-07-10 15:43 The easiest way to achieve this request is by using actions (good article by Brian Long: http://blong.com/Articles/Actions/Actions.htm, but ignore the part about ActionManager which does not exist in Lazarus). The attached demo contains three actions, one to open a file dialog, one to exit the application, and one to toggle visibility of the main menu. The short cuts CTRL+O, CTRL+X and CTRL+M are assigned to these actions, respectively. Each action is assigned to a menu item, and thus the menu items get the caption, shortcut and click handler from the associated action. Run the demo, the main menu is shown by default (by changing the code you could turn it off initially equally well). Press CTRL+M (toggle menu), and the menu disappears. Press CTRL+O and the file dialog opens although the mainmenu is hidden. Press CTRL+M again, and the menu reappears although it was hidden. As you can see, the shortcuts are working even when the menu is turned off, and all this without writing any line of code (except for the code needed to show/hide the menu). ---------------------------------------------------------------------- Milsa · 2023-07-19 16:10 This is the way. Thank you very much. ---------------------------------------------------------------------- Milsa · 2023-09-03 08:44 I have one problem with this: I have TMainMenu and TSpeedButton. TSpeedButton.Caption is empty. I set TAction to TMM and TSB. During program running TSpeedButton.Caption is set to TAction caption. I can not delete it. Please help me. ---------------------------------------------------------------------- Milsa · 2023-09-03 13:16 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   for i := 0 to ToolBar.ControlCount - 1 do    ToolBar.Controls[i].Caption := '';This is my temporary solution. Does exist any better solution? ---------------------------------------------------------------------- wp · 2023-09-03 15:12 But why do you add a TSpeedButton to a TToolbar, and not a TToolButton? Toolbuttons, by default, do not display the Caption. If you do want a Caption you must turn TToolbar.Showcaptions on, and every toolbar individually can be with or without caption by turning its TToolbButton.Showcaption on or off. And you can place the caption to the right of the icon by setting TToolBar.List to true. If you still need the TSpeedButton in the toolbar your code probably is the simplest solution. I don't know why the TSpeedButton.Caption is regenerated from the Action at runtime, and I would call this a bug, but Delphi does the same... An alternative to your solution could be to delete the Caption in the actions and to add them for the other controls using these actions. ---------------------------------------------------------------------- VincePelss · 2025-11-23 13:34 If you do not mind whitespace where the menu goes, you can just set the OwnerDraw property on the MainMenu control. This way the ShortCut keys still work, which is what I needed in my case. If you use Menu := nil the ShortCut keys no longer work.