TEdit控件获取光标键↑、↓的键值(50分)

  • 主题发起人 主题发起人 san999
  • 开始时间 开始时间
S

san999

Unregistered / Unconfirmed
GUEST, unregistred user!
在TEdit控件中如何获取光标键↑、↓的键值或
使↑作用与Tab相同,使↓作用与Shift_Tab相同。
 
↑4800H
↓5000H
 
Sorry,看错题了
 
上下光标键直接使用VK_UP,VK_DOWN就行
 
参见PiPi的:
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=200251

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
buf:TKeyBoardState;
begin
if key=VK_DOWN then
PostMessage(handle,WM_KEYDOWN,VK_TAB,0);
if key=VK_UP then
begin
GetKeyboardState(buf);
buf[VK_SHIFT]:=BYTE(buf[VK_SHIFT] or $80);
SetKeyboardState(buf);
PostMessage(handle,WM_KEYDOWN,VK_TAB,0);
end;
end;
 
模仿tab,简单一点的方法:
Edit2.onkeydown: if key=vk_down then edit3.setfocus;
if key=vk_up then edit1.setfocus;
也可以发送消息来控制.
到下一个控件的消息:WM_NEXTDLGCTL
 
WM_NEXTDLGCTL:

Parameters

wCtlFocus

Value of wParam. If the fHandle parameter is TRUE, the wCtlFocus parameter identifies the control that receives the focus. If fHandle is FALSE, wCtlFocus is a flag that indicates whether the next or previous control with the WS_TABSTOP style receives the focus. If wCtlFocus is zero, the next control receives the focus; otherwise, the previous control with the WS_TABSTOP style receives the focus.

fHandle

Value of lParam. Contains a flag that indicates how Windows uses the wCtlFocus parameter. If the fHandle parameter is TRUE, wCtlFocus is a handle associated with the control that receives the focus; otherwise, wCtlFocus is a flag that indicates whether the next or previous control with the WS_TABSTOP style receives the focus.


procedure TForm1.Button1Click(Sender: TObject);
VAR
m:TWMNextDlgCtl;
begin
m.CtlFocus:=0;
m.Handle:=false;
//m.handle=true:下一个控件;false:上一个控件
perform(WM_NEXTDLGCTL,0,0);
end;

 
多人接受答案了。
 
后退
顶部