你的窗体如果是ShowModal出来的的话,就一定在最前端。
Myform.ShowModal;

解决方案 »

  1.   

    同意楼上!
    还可以当主窗体显示之后,进入其他的窗体后,将主窗体的visible设成false;然后调用api函数,将你想要放在最前的窗体设置一下!
      

  2.   

    给你个函数!
    function ForceForegroundWindow(hwnd: THandle): boolean;
    const
      SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
      SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
    var
      ForegroundThreadID: DWORD;
      ThisThreadID      : DWORD;
      timeout           : DWORD;
    begin
      if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);  if GetForegroundWindow = hwnd then Result := true
      else begin    // Windows 98/2000 doesn't want to foreground a window
        //when some other
        // window has keyboard focus    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and
    (Win32MajorVersion > 4)) or
          ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
          ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
    (Win32MinorVersion > 0)))) then
          begin      // Code from Karl E. Peterson,www.mvps.org/vb/sample.htm
          // Converted to Delphi by Ray Lischner
          // Published in The Delphi Magazine 55, page 16      Result := false;
          ForegroundThreadID := GetWindowThreadProcessID
    (GetForegroundWindow,nil);
          ThisThreadID := GetWindowThreadPRocessId(hwnd,nil);
          if AttachThreadInput(ThisThreadID, ForegroundThreadID,
    true) then
          begin
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hwnd);
            AttachThreadInput(ThisThreadID, ForegroundThreadID,
    false);
            Result := (GetForegroundWindow = hwnd);
          end;
          if not Result then begin        // Code by Daniel P. Stasinski        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
    @timeout, 0);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
    TObject(0), SPIF_SENDCHANGE);
            BringWindowToTop(hwnd); // IE 5.5 related hack
            SetForegroundWindow(hWnd);
            SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
    TObject(timeout), SPIF_SENDCHANGE);
          end;
        end
        else begin
          BringWindowToTop(hwnd); // IE 5.5 related hack
          SetForegroundWindow(hwnd);
        end;    Result := (GetForegroundWindow = hwnd);
      end;
    end; { ForceForegroundWindow }
      

  3.   

    要使窗体显示在最上面,可以用一个API:
    setwindowpos(form1.handle,HWND_TOPmOST,LEFT,TOP,WIDTH,HEIGHT,SWP_NOACTIVE OR SWP_NOMORE OR SWP_NOSIZE)
      

  4.   

    API
    SetWindowPos(form.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE)
      

  5.   

    十分好用的一個給你吧要怎麼設置就怎麼設置:
    procedure AlwaysOnTop(Form: TForm; OnTop: Boolean);
    begin
      if OnTop then
        SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0,
        SWP_NOMOVE or SWP_NOSIZE)
      else
        SetWindowPos(Form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
        SWP_NOMOVE or SWP_NOSIZE)
    end;
      

  6.   

    只需要设置窗体的属性formstyle->fsstayontop,如果有问题再和我联系。
      

  7.   

    我这个窗体是动态创建的啊??用form.showmodal不行啊!!
      

  8.   

    将窗体的属性formstyle设为fsStayOnTop ,问题就解决了。
    新产生的窗体属性如果为fsStayOnTop,将继续在最前面。