Search code examples
delphidelphi-7

Delphi resizable bsDialog Form?


How can I make a Form (ShowModal) with BorderStyle bsDialog. but one that could still be resized and have the close button (without the Icon,Minimize, Maximize)?

I do not need it to show the size grip.


Solution

  • Here is my solution which seems to work OK:

    type
      TForm2 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
      protected
        procedure CreateWnd; override;
        procedure CreateParams(var Params: TCreateParams); override;
      public
      end;
    
    var
      Form2: TForm2;
    
    implementation
    
    {$R *.DFM}
    
    procedure TForm2.FormCreate(Sender: TObject);
    begin
      BorderIcons := [biSystemMenu];
      BorderStyle := bsSizeable;
      AutoScroll := False;
    end;
    
    procedure TForm2.CreateWnd;
    begin
      inherited;
      SendMessage(Handle, WM_SETICON, 1, 0);
    end;
    
    procedure TForm2.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
    end;
    

    IMO, This cant be done with bsDialog but the above feels and looks just like a "bsDialog" which could be resized.