如何阻止用户在编辑控件中突出显示和删除文本?

发布于 2024-12-19 23:23:38 字数 1123 浏览 3 评论 0原文

我在 DevExpress Ribbon 上有一个 TcxBarEditItem 类型的编辑控件,我正在记录其按键以更新可能要触发的功能的“浮动”列表框。

由于某种原因,TcxBarEditItem 及其父类的事件处理程序根本不像 Delphi 的普通等效项那样工作,这意味着我必须记录这些按键。

然而,我的问题是如何记录/或禁止用户执行诸如粘贴大量文本或突出显示和删除大量文本之类的操作?

这些控件似乎工作的方式意味着使用 String(TcxBarEditItem(control).EditValue) (这就是我访问控件的方式,因为它是 Command 类的成员 - TS8RibbonCommand) 实际上并不表示编辑控件中的文本,直到用户单击它为止。我尝试过做很多事情,比如以编程方式将焦点设置在其他地方并重新聚焦,但除了记录按键之外,似乎没有其他方法可以工作。

在代码片段 mirroredJumpStart 中,我复制了用户输入的内容。 RefreshJumpStart 函数采用一个字符串值,迭代列表中的所有不同字符串值,并使用 AnsiContainsString 填充列表框。

procedure TS8RibbonJumpStartEdit.KeyPress(Sender: TObject; var Key: Char);
 begin
  if (Key in ['a'..'z']) or (Key in ['A'..'Z']) or (Key in ['0'..'9']) or (Key = ' ') then
   manager.mirroredJumpStart := manager.mirroredJumpStart + Key
  else if (Key = Chr(VK_BACK)) and (Length(manager.mirroredJumpStart) <> 0) then
   Delete(manager.mirroredJumpStart, Length(manager.mirroredJumpStart), 1);
  manager.RefreshJumpStart(manager.mirroredJumpStart);
 end;

任何帮助都会很棒!

I have an Edit Control on a DevExpress Ribbon of type TcxBarEditItem which I am recording the keypresses of to update a "floating" listbox of possible functionality to fire.

For some reason, the TcxBarEditItem and it's parent classes' event handler's do not work at all like Delphi's vanilla equivalents, meaning I have to record these keypresses.

My question however, is how to record/or prohibit, the user doing things like pasting in loads of text, or highlighting and deleting loads of text?

The way in which these controls seem to work means using String(TcxBarEditItem(control).EditValue) (which is how I would access the control as it is a member of a Command class - TS8RibbonCommand) isn't actually indicative of the text in the edit control until the user clicks out of it. I've tried doing loads of things like programmatically setting focus elsewhere and refocusing but nothing else seems to work bar recording the keypresses.

In the code snippet mirroredJumpStart is my copy of what the user is typing. The RefreshJumpStart function takes a string value and iterates over all the different string values in a list and populates a Listbox using AnsiContainsString.

procedure TS8RibbonJumpStartEdit.KeyPress(Sender: TObject; var Key: Char);
 begin
  if (Key in ['a'..'z']) or (Key in ['A'..'Z']) or (Key in ['0'..'9']) or (Key = ' ') then
   manager.mirroredJumpStart := manager.mirroredJumpStart + Key
  else if (Key = Chr(VK_BACK)) and (Length(manager.mirroredJumpStart) <> 0) then
   Delete(manager.mirroredJumpStart, Length(manager.mirroredJumpStart), 1);
  manager.RefreshJumpStart(manager.mirroredJumpStart);
 end;

Any help would be great!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事灯 2024-12-26 23:23:38

假设这是一个标准的 TEdit 控件...

  • 您可以使用 MaxLength 属性限制文本量
  • 您可以通过观察事件 OnKeyDown 中的 Key 参数来捕获单个

按键几个小提示,不确定是否有帮助,因为您没有说您正在使用 TEdit

Assuming this is a standard TEdit control...

  • You can limit the amount of text by using MaxLength property
  • You can catch individual keystrokes by observing Key parameter in the event OnKeyDown

Just a couple little tips, not sure if it will help, because you don't say you're using the TEdit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文