如何阻止用户在编辑控件中突出显示和删除文本?
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设这是一个标准的 TEdit 控件...
OnKeyDown
中的Key
参数来捕获单个按键几个小提示,不确定是否有帮助,因为您没有说您正在使用
TEdit
Assuming this is a standard TEdit control...
Key
parameter in the eventOnKeyDown
Just a couple little tips, not sure if it will help, because you don't say you're using the
TEdit