How to avoid the “Open IME” popup in a StringGrid?

和自甴很熟 提交于 2019-12-22 09:08:03

问题


In a StringGrid, sometimes I get the unwanted menu below when I right-click. Is this a Windows popup?

How to I prevent this popup from appearing rather than my own?

I have goAlwaysShowEditor in my Options.

I have set StringGrid.PopupMenu to my popup.

I've set StringGrid.OnMouseDown to show my popup if it's a right click.


回答1:


You can override the virtual CreateEditor method like this way (not a good solution though, I know :-):

type
  TStringGrid = class(Grids.TStringGrid)
  protected
    function CreateEditor: TInplaceEdit; override;
  end;

implementation

function TStringGrid.CreateEditor: TInplaceEdit;
begin
  Result := inherited CreateEditor;
  TMaskEdit(Result).PopupMenu := Form1.PopupMenu1;
end;



回答2:


That is the popup menu found in every Windows EDIT control. Possible the world's most known menu (the only competition comes from the system menu). You want it, because your user's expect it (and need it). When you edit the text in a cell, the TStringGrid control actually creates a standard Windows EDIT control, which is great. And thus you get its popup menu.

In addition, to show your own popup menu (when you are not editing a cell), you don't need to set the OnMouseDown handler. It is enough to set the PopupMenu property. In fact, it is very bad to use the OnMouseDown handler to trigger a popup menu, because then the menu will only be shown when the user right-clicks the control (and not, for instance, when he presses the "context" button on his keyboard).

If you really want your own popup menu to show, even when the user is editing a cell, you really have to give him his usual options for undo, copy, cut, paste, Unicode stuff, etc., manually. Surely you don't want that?



来源:https://stackoverflow.com/questions/10676691/how-to-avoid-the-open-ime-popup-in-a-stringgrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!