在form1中有个按钮,点击后创建form2,在点击该按钮后要求鼠标形状变为沙漏,等待该form2出现后恢复原形默认的箭头鼠标形状.怎么做啊?
如果form2不是模式窗体,没有问题.(form2.show),可以变为沙漏.
可是如果form2是模式窗体,发现不起作用阿.
procedure TForm1.Button1Click(Sender: TObject);
begin
  screen.Cursor:=crHourGlass;
  form2:=Tform2.Create(Application);
  try
    form2.ShowModal;
  finally
    form2.Free;
  end;
  screen.cursor:=crDefault;
end;

解决方案 »

  1.   

    TForm类继承自TCustomForm,它的ShowModal实现方法如下:
    function TCustomForm.ShowModal: Integer;
    var
      WindowList: Pointer;
      SaveFocusCount: Integer;
      SaveCursor: TCursor;
      SaveCount: Integer;
      ActiveWindow: HWnd;
    begin
      CancelDrag;
      if Visible or not Enabled or (fsModal in FFormState) or
        (FormStyle = fsMDIChild) then
        raise EInvalidOperation.Create(SCannotShowModal);
      if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
      ReleaseCapture;
      Application.ModalStarted;
      try
      Include(FFormState, fsModal);
      ActiveWindow := GetActiveWindow;
      SaveFocusCount := FocusCount;
      Screen.FSaveFocusedList.Insert(0, Screen.FFocusedForm);
      Screen.FFocusedForm := Self;
      SaveCursor := Screen.Cursor;  //此处重新设置了鼠标形状
      Screen.Cursor := crDefault;
      //以下代码省略所以如果你如果需要实现的话,你可以在Form2中的OnShow和OnHide中设置鼠标状态,而不是在Form1中的代码中实现