TMenu lazarus / 21-General ---------------------------------------------------------------------- seghele0 · 2021-02-08 16:09 Hello Windows10 + Lazarus. How can I adjust the font.size and font.name of yhe menu (+ items) via a button. ---------------------------------------------------------------------- winni · 2021-02-08 22:56 Hi! Look at this discussion from 2016: https://forum.lazarus.freepascal.org/index.php?topic=32056.0 Winni PS .: The "Search" button in the header of this page is not only for decoration! ---------------------------------------------------------------------- seghele0 · 2021-02-09 08:48 My knowledge in programming is of a very low level. Is it possible to give a clear example of the code for this button? Thank you. ---------------------------------------------------------------------- Bart · 2021-02-09 09:12 With a simple Button's OnClick this is not going to happen... Google "delphi main menu font size" gives the following examples: https://www.tek-tips.com/viewthread.cfm?qid=1360646 http://www.delphigroups.info/2/e5/484469.html https://www.askingbox.com/question/delphi-lazarus-how-can-i-change- font-and-color-of-menu-or-popupmenu Basically set OwnerDraw to True and implement OnDrawItem and OnMeasureItem for each TMenuItem. You can do that (attach the event to the TMenuItem) in the ObjectInspector, or in code. Doing it in code also gives you the possibility to turn that off in code (Set OwnerDraw to False and the events to nil). Bart ---------------------------------------------------------------------- wp · 2021-02-09 09:21 I wonder why there is a Screen.MenuFont. Unfortunately it does not seem to be respected for menu painting. What is it good for? ---------------------------------------------------------------------- lucamar · 2021-02-09 11:08 Quote from: wp on February 09, 2021, 10:21:59 amI wonder why there is a Screen.MenuFont. Unfortunately it does not seem to be respected for menu painting. What is it good for? Like the other xxxFont properties, it's supposed to do just that: change the corresponding font. Whether it really does or not, though, depends quite a lot on the widgetset, desktop theme, etc. so it's not a very reliable way to do it. It might posibly work for custom drawn controls, but I don't know for sure. ---------------------------------------------------------------------- rvk · 2021-02-09 16:29 Quote from: seghele0 on February 08, 2021, 05:09:05 pmWindows10 + Lazarus. How can I adjust the font.size and font.name of yhe menu (+ items) via a button. On Delphi it is as simple as this (for the submenus, not the mainmenu at the top) 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 TForm1.FormCreate(Sender: TObject);begin  Screen.MenuFont.Size := 30;  MainMenu1.OwnerDraw := True;end;On Lazarus this doesn't work. On Lazarus you'll need to use the MenuDrawItem and MenuMeasureItem. But even then... making the font bigger has some side effects (just try it) and will need a lot more work to get working correctly. For using a different font it works fine. 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 TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; AState: TOwnerDrawState);begin  ACanvas.Font.Name := 'Times New Roman';  ACanvas.Font.Size := 12;  ACanvas.Brush.Style := bsClear;  ACanvas.TextOut(ARect.left, ARect.Top, TMenuItem(Sender).Caption);end; procedure TForm1.MainMenu1MeasureItem(Sender: TObject; ACanvas: TCanvas;  var AWidth, AHeight: Integer);var  NewSize: TSize;begin  ACanvas.Font.Name := 'Times New Roman';  ACanvas.Font.Size := 12;  AWidth := ACanvas.TextWidth(TMenuItem(Sender).Caption);  AHeight := ACanvas.TextHeight('Tg');end; ---------------------------------------------------------------------- wp · 2021-02-09 18:54 Quote from: rvk on February 09, 2021, 05:29:36 pmQuote from: seghele0 on February 08, 2021, 05:09:05 pmWindows10 + Lazarus. How can I adjust the font.size and font.name of yhe menu (+ items) via a button. On Delphi it is as simple as this (for the submenus, not the mainmenu at the top) 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 TForm1.FormCreate(Sender: TObject);begin  Screen.MenuFont.Size := 30;  MainMenu1.OwnerDraw := True;end;On Lazarus this doesn't work. Ah, I only had checked the top menu. But what an ugly menu is this with normal font at the top and different font in the dropdowns? ---------------------------------------------------------------------- seghele0 · 2021-02-10 10:49 rvk, Thanks. It works !!!! (see attachment). I had to remove: var   NewSize: TSize; Reason: Error Identifier not found "TSize" I suppose that it was not needed! Also an extra hint: Parameter "AState" not used. Can this be solved ? ---------------------------------------------------------------------- rvk · 2021-02-10 11:14 NewSize was indeed not needed anymore (it was a leftover because I combined two examples). The hint for AState is something from Lazarus. AState isn't used and FPC complains about parameters that aren't used. But it can't hurt (only way to get rid of it is locally disable the hint) 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 TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; {%H-}AState: TOwnerDrawState); You can also disable the specific "parameter not used" hint for your whole program. See here for the setting https://wiki.freepascal.org/Tu rn_warnings_and_hints_on_or_off#Global_IDE_option ---------------------------------------------------------------------- seghele0 · 2021-02-10 11:43 Thanks.