问题1:用户按下回车,相等于用mouse点击了speedbutton1的click事件呢问题2:程序一开始我们都会打开让用户输入用户名,正确后关闭输入用户名的界面,再打开主界面,
但我出现这样的问题,如果代码是这样 
     main.ShowModal ;
     login.Close;
那么变成直到用户关闭了main后程序才会再关闭login的界面,但这样不太顺啊
如果这样写
 main.Show ;
 login.Close;
或都这样写
 login.close
 main.ShowModal ;那么连一个界面都打不开,我想请问大家平时是怎么办的呢?

解决方案 »

  1.   

    问题1:
       初级解决办法:在每个栏位的onkeydown事件内加上:
    if KEY = VK_ENTER then Buttonxx.OnClick(Buttonxx);
    高级的方法,就是自己写个控件,加个属性什么的,省得每次都要写OnKeyDown事件问题2:在Project的source里写啊
    或者在main的FormCreate里写也是可以的,if <not login> then Application.Terminate;
      

  2.   

    在onkeypress中写点东西就可以了;
    if key = #13 then
    begin
      button1.onclick(self);
    end;
      

  3.   

    补充第二贴,记性不好,VK_ENTER应为VK_RETURN
      

  4.   

    ---------------1-------------------
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      KeyPreview := True;
    end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      case Key of
        VK_RETURN: SpeedButton1.Click;
      end;
    end;---------------2-------------------program Project1;uses
      Forms,
    //....
    {$R *.res}begin
      Application.Initialize;
      Application.CreateForm(Tmain, main);
    //....
      Application.CreateForm(Tlogin, login); //第一个创建的是主窗体//所以要和main换个位置
      login.ShowModal;
      Application.Run;
    end.
      

  5.   

    to 47522341:
    button1.onclick(self)中的self指的是目前的focus栏位
    但是按照delphi的要求,self应该传的触发事件的对象本身
      

  6.   

    1:
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if key=#13 then
      SpeedButton1.OnClick(sender);
    end;2:   //也是用户关闭了main后程序才会再关闭login的界面
     Login.Hide;
     Main.ShowModal;
     Login.Close;
      

  7.   

    formcreate
    button1.setfocus;
     button1   onkeydownif key=#13 then button1.onclick(button1);
      

  8.   

    问题1:Onkeypress中if key=#13 then button1click(Sender);
    问题2:把登录窗体的创建和显示代码写到main窗体的onshow中 如果登录失败则连主窗体一起close
      

  9.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TForm2.Create(Self) do
        try
          Show;
          Update;
        //验证
        finally
          Free;
        end;
    end;
      

  10.   

    1:
    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if key=13 then
      SpeedButton1.OnClick(SpeedButton1);
    end;2:  
     Login.Hide;
     Main.ShowModal;
     Login.Close;