导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
rhlw (lw)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 14:10:46
标题:
很奇怪的问题——关于用回车键代替TAB键
浏览:1304
加入我的收藏
楼主:
以下代码,我在随书所附的程序中能进行,但当我把它复制到我的程序后,却怎么也不能达到这个效果(也没有提示出错)——按下回车键后,光标移到下一控件;我还特地加入了第二行以备判断,但程序运行过程中也不出现该对话框,而它在原程序中可正常运行,原程序也没什么,只是仅仅有这个例子的代码,没有其他东西的。请大侠们帮我看看,谢谢! if key=#13 then Application.MessageBox('已经按下了回车键!','提示',MB_OK); if (ActiveControl is Tedit) Then Begin key:=#0; perform(WM_NEXTDLGCTL,0,0); end else if (ActiveControl is TDbgrid) Then begin With TDbgrid(ActiveControl) Do if Selectedindex<(FieldCount-1) then Selectedindex:=Selectedindex+1 else begin keybd_event(VK_TAB,KEYEVENTF_KEYUP,0, 0); //或PostMessage(DBGrid1.Handle, WM_KEYDOWN, VK_TAB, 0); end; end;
----------------------------------------------
-你的一句话,会令我少走许多弯路,衷心的多谢指点。
作者:
2003/12/24 14:14:51
1楼:
这段代码是会判断当前控件是TEdit还是TDBGrid 把它分开到各自的KeyPress中
----------------------------------------------
-
作者:
2003/12/24 15:01:31
2楼:
用第三方控件吧 song.2520.net
----------------------------------------------
-
作者:
rhlw (lw)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 15:02:53
2楼:
多谢1楼,我又看了一下原程序,发现每个控件都有这段话,但都是指向同一地方就是 procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); 为何在每个控件的ONKeyPress事件中都指向FORM的ONKeyPress事件?我需每个控件都要改动吗?这样的话,工作量也挺大的。是怎样令每个控件的ONKeyPress事件中都指向FORM的ONKeyPress事件的?能否告之?谢谢!
----------------------------------------------
-你的一句话,会令我少走许多弯路,衷心的多谢指点。
作者:
rhlw (lw)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 15:14:31
3楼:
哦,我知道了,谢谢!
----------------------------------------------
-你的一句话,会令我少走许多弯路,衷心的多谢指点。
作者:
bryan (bao)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 21:06:12
4楼:
早就不再用标准的Tedit了,自己写了个控件,省了很多麻烦:) unit MyEdit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TMyEdit = class(TEdit) private { Private declarations } FFocusColor : TColor; FNotFocusColor : TColor; protected { Protected declarations } procedure KeyPress(var Key: Char); override; procedure DoEnter; override; procedure DoExit; override; public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('MyComponents', [TMyEdit]); end; constructor TMyEdit.Create(AOwner: TComponent); begin inherited; FFocusColor := clYellow; FNotFocusColor := Color; end; procedure TMyEdit.DoEnter; begin Inherited; FNotFocusColor:= Color; Color := FFocusColor; end; procedure TMyEdit.DoExit; begin Color := FNotFocusColor; Inherited; end; procedure TMyEdit.KeyPress(var Key: Char); Var FEditTemp : TCustomForm; begin if (Key = #13) then begin FEditTemp := GetParentForm(Self); SendMessage(FEditTemp.Handle, WM_NEXTDLGCTL, 0, 0); Key := #0; exit; end; inherited; end; end.
----------------------------------------------
-
作者:
bios (阿贡)
★☆☆☆☆
-
盒子中级会员
2003/12/24 21:26:13
5楼:
----------------------------------------------