Recent

Author Topic: how to disable context menu for TMemo  (Read 2963 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
how to disable context menu for TMemo
« on: December 07, 2021, 05:29:50 pm »
I have a TMemo that is has ReadOnly true.

At runtime when I right-click on it I see active entries about Unicode, see attached. These entries are also not in English like my program.

Is this from Windows? If so, is there a way to either get rid of them or to disable them?

I use
Lazarus 2.2.0RC3 (rev lazarus_2_2_0_RC2-73-g0bf8dc1256)
FPC 3.2.3 x86_64-win64-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: how to disable context menu for TMemo
« Reply #1 on: December 07, 2021, 05:40:47 pm »
Try this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Memo1ContextPopup(Sender: TObject; MousePos: TPoint;
  2.   var Handled: Boolean);
  3. begin
  4.   Handled := True;
  5. end;

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: how to disable context menu for TMemo
« Reply #2 on: December 07, 2021, 06:00:01 pm »
Many thanks!

This disables the context menu. This helps me so far, but it would be good if I could keep the context men and only disable the entries about the Unicode character insertion.

Besides is, first now, I realize that the automatic context menu is even dangerous because for example for TComboBox it contains the entry to delete the current content. And when the users does this, my code fails since I was not aware that the user can do this.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: how to disable context menu for TMemo
« Reply #3 on: December 07, 2021, 06:30:30 pm »
For your purposes I suggest you don't write an OnContextPopup handler at all.
Instead, simply write your own memo popup which does exactly what you want, without any system/Unicode stuff.
Here's a basic skeleton (of course you need to add at least menuitem OnClick  handlers):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   mi1, mi2: TMenuItem;
  4.   pop: TPopupMenu;
  5. begin
  6.   pop := TPopupMenu.Create(Memo1);
  7.   pop.AutoPopup := True;
  8.   mi1 := TMenuItem.Create(pop);
  9.   mi1.Caption := 'Item1';
  10.   mi2 := TMenuItem.Create(pop);
  11.   mi2.Caption := 'Item2';
  12.   pop.Items.Add([mi1, mi2]);
  13.   Memo1.PopupMenu := pop;
  14. end;

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: how to disable context menu for TMemo
« Reply #4 on: December 07, 2021, 06:48:27 pm »
For your purposes I suggest you don't write an OnContextPopup handler at all.
Instead, simply write your own memo popup which does exactly what you want, without any system/Unicode stuff.

I could do so, but I want to benefit from the entries that are already defined. These are "Insert", "Cut" etc. it seems that they are added by Windows. So what I need is a way to control these context menu entries. So for example the "Undo" entry is very helpful so for an enabled TMemo this entry is a benefit.
So I don't want to rewrite what Windows already added to the context menu.

 

TinyPortal © 2005-2018