能力值:
( LV12,RANK:450 )
|
-
-
2 楼
在主窗口的 FormKeyDown 事件中,拦截 Ctrl 键,当Ctrl键被按下时,利用SetFocus命令,将窗体上某个不相关的组件设置聚集即可。
当然你还可以再判断 C 键被按下,但一般没有必要。
|
能力值:
( LV9,RANK:210 )
|
-
-
3 楼
能否再详细一些!谢谢!
|
能力值:
( LV12,RANK:450 )
|
-
-
4 楼
假设窗体上有两个组件,一个是Memo,一个是Button键,一个退出程序的Button键,当 Ctrl 键被按下时,将聚集控制转移到 Button 键,这样,别人就没有办法将 Memo 中的内容拷贝出去。下面是代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if ssCtrl in Shift then
// if Key = VK_CONTROL then
Button1.SetFocus;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
end.
其中:
if ssCtrl in Shift then
if Key = VK_CONTROL then
这两句的作用是一样的,随便你喜欢使用那一句,但第一句可以将判断扩充的更详细,例如:
if ssCtrl in Shift then
if Key = VK_C then
Button1.SetFocus;
这样就只控制拷贝键 Ctrl-C。
|
能力值:
( LV9,RANK:210 )
|
-
-
5 楼
感谢楼上朋友的帮助
|
能力值:
( LV12,RANK:450 )
|
-
-
6 楼
忘了一点,那就是Memo组件的KeyDown事件或别的需要控制的组件的KeyDown需要将 OnKeyDown 指向 FormKeyDown。
|
|
|