在一个界面上有三个控件,第一个是edit1,第二个是TRadioGroup1,第三个是edit2,我想实现如下功能当按回车键时光标从edit1移到TRadioGroup1,再按回车键时光标从TRadioGroup1移到edit2。请问要如果实现呢?注意TRadioGroup1没有OnKeyDown 或 OnKeyPress事件。谢谢

解决方案 »

  1.   

    可以啊只要转移以下焦点就可以了
    事件OnEnter里写就可以
      

  2.   

    procedure Tw_f_zy_add.RG_xbEnter(Sender: TObject);
    begin
      if (key=13) then
         edit2.SetFocus;
    end;
    编译不了,[Error] w_u_zy_add.pas(236): Undeclared identifier: 'key'
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        RadioGroup1: TRadioGroup;
        Edit2: TEdit;
        procedure Edit1KeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
      private
        procedure OnKeyD(Sender: TObject; var Key: Word; Shift: TShiftState);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key=VK_RETURN then
      begin
        RadioGroup1.Buttons[RadioGroup1.ItemIndex].SetFocus;
        RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd;
      end;
    end;procedure TForm1.OnKeyD(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      edit2.SetFocus;
    end;end.
      

  4.   

    还有一点小问题要完善,就是当我用方向键来操作改变了RadioGroup1的itemindex值之后,再敲回车键,这时候光标跳不到EDIT2。请再帮忙看看怎么改善这个程序。
      

  5.   

    呵呵,我写的那个程序是临时性,你要真的用的话应该这样
    在Form的ONCreate事件中
    for i:= 0 to   Radiogroup1.Items.Count-1 do
      RadioGroup1.Buttons[i].OnKeyDown:= Onkeyd;也就是事先将Group中的每个Button的OnKeyDown事件都赋值为Onkeyd,然后去掉Edit1KeyDown中的下面这句
      RadioGroup1.Buttons[RadioGroup1.ItemIndex].OnKeyDown:= Onkeyd;
      
      

  6.   

    procedure Tw_f_zy_add.RG_xbEnter(Sender: TObject);
    begin
      if (key=13) then
         edit2.SetFocus;
    end;