Delphi:StringGrid,位置和上下文菜单 [英] Delphi: StringGrid, position and Context Menu

查看:442
本文介绍了Delphi:StringGrid,位置和上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用TStringGrid和弹出菜单时遇到问题

I'm having a problem with using a TStringGrid and Popup menu

我想知道选择一个项目时上次激活的单元格的行/列从我的弹出菜单中。但是,当我单击弹出菜单时,StringGrid.Row返回为-1。

I want to know the Row / Column of the cell that was last active when select an item from my Popup menu. However when I click on the popup menu, the StringGrid.Row is returned as -1.

我尝试将MouseToCell用作OnClick的一部分,即使在设置SG之后.PopUp菜单例程中的行仍然返回-1。我怀疑问题是网格失去了焦点。

I've tried using MouseToCell as part of OnClick, but even after setting SG.Row it still returns as -1 in the PopUp menus routines... I suspect that the problem is the Grid losing the focus.

对此是否有解决方案不需要OnClick设置全局变量吗?

Are there any solutions to this that don't require OnClick setting a global variable?

我正在使用链接到弹出菜单上各项的操作列表,以确保操作之间的一致性。工具栏和弹出菜单

I'm using an Action List linked to the items on the Popup Menu to make sure that the actions are consistent between the toolbar and the Popup Menu

推荐答案

恐怕我不完全理解您的意思。当我在字符串网格中的单元格上单击鼠标左键时,它被选中,但是当我右键单击它时,它未被选中。右键单击时,将显示弹出菜单(如果已分配),并且在 MenuItemClick 上,我可以轻松阅读 col 当前选中。参见示例视频

I am afraid that I do not fully understand what you mean. When I left-click a cell in a string grid, it gets selected, but not when I right-click it. When I right-click it, the popup menu is shown (if assigned), and on MenuItemClick I can easily read the row and col currently selected. See example video.

I guess 实际上是您想要的:您想要右键单击来更改活动单元格,也要单击鼠标左键。这很容易做到:

I guess that you actually want this: you want right-clicks to change the active cell as well as left-clicks. This is easily done:

procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    StringGrid1.Perform(WM_LBUTTONDOWN, 0, MakeLParam(Word(X), Word(Y)));
end;

这篇关于Delphi:StringGrid,位置和上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆