Recent

Author Topic: TMenuItem, How to insert esc chars like a TAB in the Caption and show "underline  (Read 426 times)

jamie

  • Hero Member
  • *****
  • Posts: 6686
As it states. Translating some C++ code, a "\t" is used for the TAB so I can get even spaced captions between the title and remainder of the caption
« Last Edit: October 06, 2024, 10:48:47 pm by jamie »
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 3477
Re: TMenuItem, How to insert esc chars like a TAB in the Caption?
« Reply #1 on: October 06, 2024, 09:46:41 pm »
usually see wikipedia but I do not know if tmenuitem captions honours that. If you have difficulty instering the caption in the object inspector then you might want and try literally writing the caption down somewhere else then copy-paste as tab does something else in the IDE.
This tagline is powered by AI

VisualLab

  • Hero Member
  • *****
  • Posts: 519
Re: TMenuItem, How to insert esc chars like a TAB in the Caption?
« Reply #2 on: October 06, 2024, 09:50:42 pm »
Quite a peculiar need (not that it's a criticism). Out of curiosity, I'll ask: which program uses something like that? Because I don't think I've come across anything like that before (or I'm not aware of it).

jamie

  • Hero Member
  • *****
  • Posts: 6686
Re: TMenuItem, How to insert esc chars like a TAB in the Caption?
« Reply #3 on: October 06, 2024, 09:53:57 pm »
in C/C++ you can use control chars to insert items like TABS,  new Lines etc.

In this example, the 'XYZ\tABC' would result in a nicely formatted caption in the menu of "XYZ     ABC" etc.

I know there is a json string function that can do this, but obviously its not in here?

If you look at various menu examples the accelerator keys are spaced to the right evenly, so all menu items dropped down are formatted.
« Last Edit: October 06, 2024, 09:56:59 pm by jamie »
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6686
Re: TMenuItem, How to insert esc chars like a TAB in the Caption?
« Reply #4 on: October 06, 2024, 10:05:13 pm »
I also noticed that while in the Menu Designer, the Acell letters are underlined, at run time, they are not?

apparently Laz does not intepret strings like this for control chars, I need to fill in a property field per item, but doing so, I still don't see a underline..

I'll be back, strange it will not accept escape chars like this.
« Last Edit: October 06, 2024, 10:09:58 pm by jamie »
The only true wisdom is knowing you know nothing

VisualLab

  • Hero Member
  • *****
  • Posts: 519
Re: TMenuItem, How to insert esc chars like a TAB in the Caption?
« Reply #5 on: October 06, 2024, 10:57:22 pm »
If you look at various menu examples the accelerator keys are spaced to the right evenly, so all menu items dropped down are formatted.

Ah, that's what you mean. I just checked in Lazarus (which is written using Lazarus - LCL). Menu items (not all of them) contain keyboard shortcuts. And they are aligned to the right edge of the expanded menu. I always added information about keyboard shortcuts (accelerator keys) in the ShortCut property of a specific TMenuItem. And they always displayed nicely after showing the menu section during program runtime.

I also noticed that while in the Menu Designer, the Acell letters are underlined, at run time, they are not?

apparently Laz does not intepret strings like this for control chars, I need to fill in a property field per item, but doing so, I still don't see a underline..

I'll be back, strange it will not accept escape chars like this.

They show up when you press the Alt key on your keyboard. I think in the older days (Windows 3.11 and earlier) these underlines were permanent, but then MS changed it.

P.S. At least that's how it works in Windows. I don't have Linux running at the moment, but I'll try to check tomorrow.
« Last Edit: October 06, 2024, 11:00:56 pm by VisualLab »

jamie

  • Hero Member
  • *****
  • Posts: 6686
If you press a relative key to the menu item with the supposed underline, that LETTER is used to execute the menu item.

But if you can't see it when you manually open it, it's a guess.

They are supposed to be highlighted at all times whenever the "&" is Infront.

You don't need the ALT+letter to execute the target menu when the menu is already opened, but it is supposed to show it, so you know what key to press.

The ALT+.... only works when the menus are closed up//.


The only true wisdom is knowing you know nothing

VisualLab

  • Hero Member
  • *****
  • Posts: 519
If you press a relative key to the menu item with the supposed underline, that LETTER is used to execute the menu item.

But if you can't see it when you manually open it, it's a guess.

They are supposed to be highlighted at all times whenever the "&" is Infront.

You don't need the ALT+letter to execute the target menu when the menu is already opened, but it is supposed to show it, so you know what key to press.

The ALT+.... only works when the menus are closed up//.

I press the Alt key (the first time). The letters in the names of the main menu sections appear underlined. Then I press the Alt+... key combination (e.g. Alt+F for the "File" section). The indicated main menu section appears expanded. Then I can use the arrow keys or a keyboard shortcut.

jamie

  • Hero Member
  • *****
  • Posts: 6686
Yeah, but they are supposed to show when manually open the drop down.

In anycase, I fixed the issue by using OWnerDraw and now they show property, also with that, there is no longer flickering in the main menu when you move the form around, which has been there for a long time.

Thanks for the help.

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12409
How to insert esc chars like a TAB in the Caption and show "underline

As it states. Translating some C++ code, a "\t" is used for the TAB so I can get even spaced captions between the title and remainder of the caption
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender:TObject);
  2. begin
  3.   MenuItem2.Caption := 'Test'#9'test';
  4.   MenuItem3.Caption := 'ABC'#9'test';
  5.   MenuItem4.Caption := 'MenuItem4'#9'test';    
  6. end;
But be warned that the alignment of the part after the tab may depend on the length of the part before it...

jamie

  • Hero Member
  • *****
  • Posts: 6686
Yes, I got it to align the way I wanted it to show, but kind of disappointed about how the underscores are working, I also solved that with the owner draw.
The only true wisdom is knowing you know nothing

VisualLab

  • Hero Member
  • *****
  • Posts: 519
I have now tried the accelerator keys in various Windows programs. It turns out that the action of accelerator keys in their main menu varies (some work as expected, some do not). This means that a lot depends on the programmer, and perhaps also on the libraries, not just on the OS. Interestingly, even those written in Java work correctly (NetBeans, SceneBuilder).

 

TinyPortal © 2005-2018