设置控件taborder后 if (Key = #13) then begin Key := #0; Perform(Wm_NextDlgCtl,0,0); end;
不行,使用回车键时,好像不能激活onkeypress事件。
procedure TF_comp.DoEnterAsTab(var Msg: TMsg; var Handled: Boolean); begin if Msg.Message = WM_KEYDOWN then begin if Msg.wParam = VK_RETURN then Keybd_event(VK_TAB, 0, 0, 0); end; //if end;
需要你声明procedure DoEnterAsTab(var Msg: TMsg; var Handled: Boolean); 然后在Tform1.FormCreate中Application.OnMessage := DoEnterAsTab;
呵呵,刚刚看错了,看成DBGRID了用回车代替方向键的下就行了,和代替TAB一样procedure TF_comp.DoEnterAsDOWN(var Msg: TMsg; var Handled: Boolean); begin if Msg.Message = WM_KEYDOWN then begin if Msg.wParam = VK_RETURN then Keybd_event(VK_DOWN, 0, 0, 0); end; //if end;
我刚刚看了一下,这个控件有个GetTabOrderList方法,重新默认并从排序列表中删除所有子组件,并返回一个空的列表。TDBCtrGrid对象执行自己的TAB键处理方法,可在数据库排序中的所有面板上循环移动。难道这个控件自动调用这个方法?那为什么直接按tab就好用? 我刚刚试了一下,在它上面的控件的onexit事件里设置光标就可以了procedure TForm1.DBEdit1Exit(Sender: TObject); begin dbedit2.SetFocus end;这个控件还有很多不懂的地方,希望来个明白的给讲讲
DBCtrlGrid内的控件的taborder只能是从零开始,会与外面的控件重复,所以当我们在DBCtrlGrid上使用回车代替tab时,就会出问题所以这个问题的解决办法就是(以我的为例,有两个DBEDIT和一个DBComboBox)procedure Tform1.DoEnterAsDown(var Msg: TMsg; var Handled: Boolean); begin if Msg.Message = WM_KEYDOWN then begin if Msg.wParam = VK_RETURN then Keybd_event(VK_down, 0, 0, 0); end; //if end;procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := DoEnterAsDown; end;procedure TForm1.DBEdit1Exit(Sender: TObject); begin dbedit2.SetFocus end;procedure TForm1.DBEdit2Exit(Sender: TObject); begin DBComboBox1.SetFocus end;procedure TForm1.DBComboBox1Exit(Sender: TObject); begin DBCtrlGrid1.SetFocus; end; 这个方法用起来不是太好,因为焦点到了DBCtrlGrid时,还要再回车,才能到第一个控件内。 要是谁有更好的方法,请告诉我。
if key=#13 then begin with dbgrid1 do begin if selectedindex=1 then selectedindex:=2; if selectedindex=2 then begin table1.append; selectedinded:=0; end; if selectedindex=0 then selectedindex:=1; end;
呵呵。楼上的和我已开始一样看错了 楼下的看仔细了是 DB Ctrl Grid 控件别再看成 dbgrid 了
if (Key = #13) then
begin
Key := #0;
Perform(Wm_NextDlgCtl,0,0);
end;
begin
if Msg.Message = WM_KEYDOWN then
begin
if Msg.wParam = VK_RETURN then
Keybd_event(VK_TAB, 0, 0, 0);
end; //if
end;
然后在Tform1.FormCreate中Application.OnMessage := DoEnterAsTab;
begin
if Msg.Message = WM_KEYDOWN then
begin
if Msg.wParam = VK_RETURN then
Keybd_event(VK_DOWN, 0, 0, 0);
end; //if
end;
Perform(Wm_NextDlgCtl,0,0);
加到后面就可以了,多谢了。
一开始用回车台代替的TAB ,所以它就跑到另一个控件了后来回车台代替的是下,所以它就不能实现tab的切换功能
要不这样,在每一个控键的onkeypress里 if key=#13 then
他的下一个控件.SetFocus;
后,所有的回车都转到第二个控件。
我刚刚试了一下,在它上面的控件的onexit事件里设置光标就可以了procedure TForm1.DBEdit1Exit(Sender: TObject);
begin
dbedit2.SetFocus
end;这个控件还有很多不懂的地方,希望来个明白的给讲讲
begin
if Msg.Message = WM_KEYDOWN then
begin
if Msg.wParam = VK_RETURN then
Keybd_event(VK_down, 0, 0, 0);
end; //if
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := DoEnterAsDown;
end;procedure TForm1.DBEdit1Exit(Sender: TObject);
begin
dbedit2.SetFocus
end;procedure TForm1.DBEdit2Exit(Sender: TObject);
begin
DBComboBox1.SetFocus
end;procedure TForm1.DBComboBox1Exit(Sender: TObject);
begin
DBCtrlGrid1.SetFocus;
end;
这个方法用起来不是太好,因为焦点到了DBCtrlGrid时,还要再回车,才能到第一个控件内。
要是谁有更好的方法,请告诉我。
begin
with dbgrid1 do
begin
if selectedindex=1 then
selectedindex:=2;
if selectedindex=2 then
begin
table1.append;
selectedinded:=0;
end;
if selectedindex=0 then
selectedindex:=1;
end;
楼下的看仔细了是 DB Ctrl Grid 控件别再看成 dbgrid 了