http://delphi.about.com/od/adptips2004/a/bltip0804_4.htm

Here's how to implement the code for the CTRL+A key combination ("Select All") for TMemo or TDBMemo:

~~~~~~~~~~~~~~~~~~~~~~~~~
Just drop a memo (Memo1:TMemo) on a form (Form1:TForm) and handle the OnKeyDown event for Memo1 as:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState) ;
begin
   if (Key = Ord('A')) and (ssCtrl in Shift) then
   begin
     TMemo(Sender).SelectAll;
     Key := 0; //这里即使为0,Windows系统还是能继续接到按键的信息,然后就会导致 BEEP 声音(win7是当当的声音),因为这里只是 KeyDown。
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Note: here's how to check the state of CTRL, ALT and SHIFT keys.

http://stackoverflow.com/questions/8466747/automatically-allowing-ctrla-to-select-all-in-a-tmemo

In Delphi 7's TMemo control, an attempt to do the key combo Ctrl + A to select all does not do anything (doesn't select all). So I've made this procedure:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
C: String;
begin
if ssCtrl in Shift then begin
C:= LowerCase(Char(Key));
if C = 'a' then begin
Memo1.SelectAll;
end;
end;
end;

Is there a trick so that I don't have to do this procedure? And if not, then does this procedure look OK?

asked Dec 11 '11 at 19:24
Jerry Dodge
8,642957147
 
3  
Personally I'd sooner create a component derived from the standard memo and handle the key press there so that you don't need to pollute all your forms with special handling code. –  David Heffernan Dec 11 '11 at 19:33
2  
@David: Do you know if a standard Windows edit control in multiline mode disallows the Ctrl+A command, or if there is a problem with the VCL wrapper? (TheTEdit handles Ctrl+A as one would expect.) –  Andreas Rejbrand Dec 11 '11 at 19:35
1  
@Andreas Once I can get to a machine with a compiler I'll try and produce a raw win32 petzold prog and check it out. –  David Heffernan Dec 11 '11 at 19:51
1  
It seems to be an OS issue with no documented explanation. Many posts about it are just based on code this by your own. –  TLama Dec 11 '11 at 19:54
2  
@David: If I am not mistaken, Raymond asks his readers every now and then about things to write about. This would be an interesting topic. –  Andreas Rejbrand Dec 11 '11 at 20:56

1 Answer

up vote 20down voteaccepted

This is more elegant:

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = ^A then 牛人搞了一个更简单的
begin
(Sender as TMemo).SelectAll;
Key := #0; 这里 为#0后,就没有BEEP声音了,Windows系统接不到按了什么键。
end;
end;
answered Dec 11 '11 at 19:30
Andreas Rejbrand
60.4k3152244
 
4  
I know I'm going on a bit but could you possibly explain the ^A for the uninitiated (e.g. me!) –  David Heffernan Dec 11 '11 at 19:44
9  
The Ctrl+A keystroke is send as a character with ordinal value 1 (Ctrl+B as 2, Ctrl+C as 3, etc.). Basically I think that this is a remnant from older times. These 'characters' are usually written ^A^B, etc., and Delphi supports these. You can see them in ASCII tables, like at Wikipedia. –  Andreas Rejbrand Dec 11 '11 at 19:48
2  
Haven't seen that for years, must be from TP days. –  Tony Hopkinson Dec 11 '11 at 20:01
5  
@Jerry: The result is not exactly the same. Your code will not handle the annoying 'beep' sound! –  Andreas Rejbrand Dec 11 '11 at 21:46 这个结果和你的代码效果,不是完全相同的,你的代码没有处理这个烦人的 BEEP声音。
2  
@Jerry - AFAIK there's no fix to this. This is the default behavior of a windows edit control, you can read about expected behavior of an edit control here. –  Sertac Akyuz Dec 11 '11 at 22:43

Your Answer

How to add the "Select All (CTRL+A)" functionality to TMemo/TDBMemo

Title: How to add the "Select All (CTRL+A)" functionality to TMemo/TDBMemo

Question: How to add the "Select All (CTRL+A)" functionality to TMemo/TDBMemo.

Answer:
To implement the code for the CTRL+A key combination ("Select All") for TMemo, TDBMemo or any of it's descendants implement the following code on the OnKeyDownEvent:

procedure OnKeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState) ;
begin
   if (Key = Ord('A')) and (ssCtrl in Shift) then
   begin
     TMemo(Sender).SelectAll;
     Key := 0;
   end;
end;

from: http://delphi.cjcsoft.net//viewthread.php?tid=45347

 
 
=========================================
if ssCtrl in shift then
  begin
    if (Key = Ord('c')) or (Key = Ord('C')) then
      ShowMessage('Ctrl+C');

end;

先判断是否按下ctrl才是正确的次序。

TMemo Ctrl + A的更多相关文章

  1. Delphi 记事本 TMemo

    Windows记事本记事本     描述:     用Delphi模仿的Windows记事本 界面和功能都和Windows的记事本一样,是用Memo实现的而不是RichEdit 可以执行以下功能 文件 ...

  2. Delphi TMemo 可以显示、编辑多行文本

    多行编辑框组件(TMemo)TMemo组件可以显示.编辑多行文本,是一个标准的Windows多行编辑组件.对一些比较多的文本内容可以利用TMemo组件来显示.编辑. 1.TMemo组件的典型用法 TM ...

  3. Windows cmd 长时间不输出新内容 直到按下ctrl + c 取消或者回车的解决办法

    换了一台新电脑, 在使用 ant 拷贝大量文件的时候 cmd 窗口过了很久没有继续输出新的内容,远远超过平时的耗时, 以为已经卡死 按下 ctrl + c 取消, 这时并没有取消, 而是输出了新内容, ...

  4. [No00008B]远程桌面发送“Ctrl+Alt+Delete”组合键调用任务管理器

    向远程桌面发送"Ctrl+Alt+Delete"组合键的两种方法 1.在本地按下Ctrl+Alt+End,可以成功发送"Ctrl+Alt+Delete"组合键! ...

  5. Linux下的ctrl常用组合键

    在linux的命令模式下使用ctrl组合键能让操作更便捷. ctrl + k -- 剪切光标及其后边的内容: ctrl + u -- 剪切光标之前的内容: ctrl + y -- 在光标处粘贴上两个命 ...

  6. 鼠标上下滑动总是放大缩小页面,按住ctrl+0

    鼠标上下滑动总是放大缩小页面,可能是ctrl键失灵了,幸好键盘有两个ctrl键,按住ctrl+0,页面就正常了,吓死宝宝了,~~~~(>_<)~~~~

  7. eclipse中ctrl+h默认打开是JavaSearch,怎么设置成默认打开是FileSearch

    window->preferences->General->keys. 找到File Search(有搜索框的,可以搜索),然后在下方 Binding按下ctrl +h .

  8. CapsLock与ctrl的键位修改

    windows下修改方式: linux下修改方式: 在用户目录下新建文档命名为keychange.sh 编辑以下内容: remove Lock = Caps_Lock remove Control = ...

  9. windows 中去除Ctrl+Alt+Del才能登录

    安装windows 7后登录的时候有一样很麻烦的步骤是需要先按Ctrl+Alt+Del,才能输入用户密码进行登录.这里笔者介绍一下如何取消这个东西. 点击“开始菜单”,点击“控制面板”. [管理工具] ...

随机推荐

  1. Ruby基础教程

    一.Ruby基础知识 1.关于Ruby Ruby是脚本语言 Ruby是面向对象语言 Ruby是跨平台语言 Ruby是开放源码软件 2.Ruby入门书籍推荐 <Ruby.Programming向R ...

  2. 利用RNN(lstm)生成文本【转】

    本文转载自:https://www.jianshu.com/p/1a4f7f5b05ae 致谢以及参考 最近在做序列化标注项目,试着理解rnn的设计结构以及tensorflow中的具体实现方法.在知乎 ...

  3. Several Service Control Manager Issues (Event ID's 7000, 7009, 7011)

    https://answers.microsoft.com/en-us/windows/forum/windows_7-performance/several-service-control-mana ...

  4. C# 获取SQL Server所有的数据库名称

    参考文章:http://www.cnblogs.com/Abel_cn/archive/2008/12/09/1351425.html http://blog.csdn.net/friendan/ar ...

  5. CenterOS下从零起步简单部署RockMongo

    使用Mongodb,对于调试Query,查看Collection等状态,有Rockmongo是非常方便的. 研究了下Rockmongo的部署,主要是依赖PHP环境的web服务器,当前有两种服务器,一种 ...

  6. mysql时间格式化函数日期格式h和H区别

    本文为博主原创,未经允许不得转载: 今天碰到一个问题,发现项目中有一个统计图的数据和时间格式没有对应准确,统计图要描述的是操作次数和操作时间的关系, 但很奇怪的是操作次数对应的时间却是凌晨,实际应用中 ...

  7. UVa 11235 频繁出现的数值

    https://vjudge.net/problem/UVA-11235 题意: 给出一个非降序排列的整数数组a1,a2,...,an,你的任务是对于一系列询问(i,j),回答ai,ai+1,...a ...

  8. zeptojs库解读3之ajax模块

    对于ajax,三步骤,第一,创建xhr对象:第二,发送请求:第三,处理响应. 但在编写过程中,实际中会碰到以下问题, 1.超时 2.跨域 3.后退 解决方法: 1.超时 设置定时器,规定的时间内未返回 ...

  9. shell 清空指定大小的日志文件

    #!/bin/bash # 当/var/log/syslog大于68B时 if ! [ -f /var/log/syslog ] then echo "file not exist!&quo ...

  10. Jmeter 中对响应报文处理后断言用到BeanShell Assertion

    Jmeter中常用的断言可以是Response Assertion 如果需要对响应报文中的某个字符串进行解码,对解码之后的值在进行断言要怎么做呢? 仔细观察一下,可以用下面俩个元件 Regular E ...