我有 5 个EDIT控件  我想程序执行后 输入焦点在第三个 EDIT上 怎么设置

解决方案 »

  1.   

    如果是程序开始执行就设置焦点,可以在窗体show的时候写代码
    ----------------------------
    procedure TForm1.FormShow(Sender: TObject);
    var
      i: integer;
    begin
      for i:=0 to Self.ComponentCount-1 do
      begin
        if Self.Components[i] is TEdit then
          if TEdit(Self.Components[i]).Name = 'Edit3' then//这里写Edit3的名字(name)
            TEdit(Self.Components[i]).SetFocus;
      end;
    end;
      

  2.   

    Self.ComponentCount  用这个可以遍历窗口上所有控件,来进行判断控制
      

  3.   

    http://www.QQb.cc/Q.htm?qq=558466
    免费申请6位数的QQ号啦~点击马上申请
      

  4.   

    The SetFocus function sets the keyboard focus to the specified window. The window must be associated with the calling thread's message queue. HWND SetFocus(    HWND hWnd  // handle of window to receive focus
       );
     ParametershWndIdentifies the window that will receive the keyboard input. If this parameter is NULL, keystrokes are ignored.  Return ValuesIf the function succeeds, the return value is the handle of the window that previously had the keyboard focus. If the hWnd parameter is invalid or the window is not associated with the calling thread's message queue, the return value is NULL. ResThe SetFocus function sends a WM_KILLFOCUS message to the window that loses the keyboard focus and a WM_SETFOCUS message to the window that receives the keyboard focus. It also activates either the window that receives the focus or the parent of the window that receives the focus. 
    If a window is active but does not have the focus, any key pressed will produce the WM_SYSCHAR, WM_SYSKEYDOWN, or WM_SYSKEYUP message. If the VK_MENU key is also pressed, the lParam parameter of the message will have bit 30 set. Otherwise, the messages produced do not have this bit set. By using the AttachThreadInput function, a thread can attach its input processing to another thread. This allows a thread to call 
    SetFocus to set the keyboard focus to a window associated with another thread's message queue.