Windows OS contextmenu

Having a textfield control on a form, it gives the user the option to past text into it using the Windows context menu.
We can create our own context menu on the textfield, with our own options, works fine, but when the user presses the escape-button he will anyway get the Windows contextmenu for the textfield.
My question:
Is anybody aware of a method (declare) which stops Windows from presenting any OS-contextmenu in our application, with respect to our own contextmenu’s. ?

Could you enumerate the exact steps to replicate this?

Very simple:

  1. new project
  2. Textfield on Window1
  3. Run
    Now you can of course type text into the textfield. With a few lines of code you could limit the valid keys for input in the keydown event of the textfield-control, for example only numeric, left- and right arrows and dot.
    What undermines this is the possibility to right mouse click on the Textfield, and the Windows context menu gives you the possibility to paste any text from the clipboard into the textfield-control. And yes, then you could have some code in the textchange event to validate and correct, but that’s actually more like damage control. I prefer not having the possibility to paste anything in it at all. So, looking for disabling the Windows context menu on text-input controls.

Heh. I got that, but you said something about pressing the ESC key causing this issue.

And how are you making the contextualmenu? Using the ConstructContextualMenu event? Or are you creating a menu yourself and showing that?

[quote=348580:@Joost Rongen]Having a textfield control on a form, it gives the user the option to past text into it using the Windows context menu.
We can create our own context menu on the textfield, with our own options, works fine, but when the user presses the escape-button he will anyway get the Windows contextmenu for the textfield.[/quote]

1. New Desktop Project 2. Drop a TextField into Window1 3. In ConstructContextualMenu Event add Code to add MenuItems to the base MenuItem 4. Run the App on Windows 5. RightClick into the TextField 6. While the ContextualMenu is shown, press the ESC-Key

I tried to create Workarounds with KeyDown/ContextualMenuAction Events without luck.

BTW: More worse is that if you paste with an EditPaste clone Context-MenuItem, the Windows System ContextMenu can also open on Windows.

Looks like it somehow depends on if you have additional MenuItems beside EditCut, EditCopy, … in your Menu or if you “do something” in the ContextMenuAction Event. I am out of spare time to test right now.

And if i rightclick in a TextField with such a ContextualMenu, the “Xojo” ContextMenu shows up. If i do another rightclick outside of this ContextMenu right beside ConextMenu, the Windows ContextMenu will appear. If i do the same but the 2nd rightclick is left beside the Xojo ContextMenu, no Windows ContextMenu will open.

All very strange… :wink:

Tested with X2017 R2. Build on Sierra as 32Bit App. App running under Windows 10 64Bit.

feedback://showreport?report_id=49483

I test back to 2015r1 and the behavior is the same. What is actually happening is that windows system menu is ‘shown’ when the Xojo context menu is shown but it is invisible. To verify type some text into the textfield, right click to show the xojo menu, click to the right of the first menu item (assuming your menu is not as wide as the system menu) . Verify the the undo menu item was executed, because newly entered text is cleared.

In the TextArea the result is the same except the second context is a clone of the xojo context menu instead of the system menu.

The fix is to return true from the ConstructContextualMenu event.

The bug is really that when not returning true the Xojo contect menu is still displayed contrary to the docs.

from the LR

[quote]If you return False, the event is passed up the parent hierarchy.

If you return True, the contextual menu is displayed.[/quote]

How will you prevent a Ctrl+V paste? Returning true from the KeyDown event doesn’t work.

EDIT: Strange the mask works properly to prevent paste with Ctrl+V, but the mask does not filter properly the context menu paste.

You can subclass the control and add an empty menu handler for EditPaste.

Thanks. This is one.

This did not work on my side. Could you please submit a small testproject Tim ?

Very simple: In the otherwise empty ConstructContextualMenu event simply return true.

Understood, but is just a part of the solution. It’s still possible to use Ctrl-V (Windows) to put some text in the control.

Here you go. https://www.dropbox.com/s/8up4i34vka8gq1p/Textfield%20No%20Paste.rbp?dl=1

Very good but try Ctrl+Shift+V

Just verified setting a mask will prevent Shift+Ctrl+V.

Thanks @Tim Hare and @Neil Burkholder