更改ShowMessage对话框的标题和属性

Shi*_*h11 5 delphi delphi-2006

在Delphi中你可以更改ShowMessage对话框的标题,因为默认情况下它是我的exe名称.

我可以改变背景颜色,大小相同吗?

zz1*_*433 17

您可以使用delphi的CreateMessageDialog函数创建自己的自定义对话框.

示例如下:

var
  Dlg: TForm;
begin
  Dlg := CreateMessageDialog('message', mtInformation, [mbOk], mbOK);
  // Treat Dlg like any other form

  Dlg.Caption := 'Hello World';

  try
    // The message label is named 'message'
    with TLabel(Dlg.FindComponent('message')) do
    begin
      Font.Style := [fsUnderline];

      // extraordinary code goes here
    end;

    // The icon is named... icon
    with TPicture(Dlg.FindComponent('icon')) do
    begin
      // more amazing code regarding the icon
    end;

    Dlg.ShowModal;
  finally
    Dlg.Free;
  end;
Run Code Online (Sandbox Code Playgroud)

当然,您也可以动态插入其他组件以及该表单.


Dav*_*nan 6

该对话框将使用内容Application.Title作为标题.所以你可以在打电话之前设置它ShowMessage.

但是,如果要显示具有不同标题的多个对话框,则调用Windows MessageBox函数会更方便.当然,如果你有一个旧版本的Delphi,这将导致你的对话更原始的感觉.

procedure MyShowMessage(const Msg, Caption: string);
begin
  MessageBox(GetParentWindowHandleForDialog, PChar(Msg), PChar(Caption), MB_OK);
end;

function GetParentWindowHandleForDialog: HWND;
begin
  //we must be careful that the handle we use here doesn't get closed while the dialog is showing
  if Assigned(Screen.ActiveCustomForm) then begin
    Result := Screen.ActiveCustomForm.Handle;
  end else if Assigned(Application.MainForm) then begin
    Result := Application.MainFormHandle;
  end else begin
    Result := Application.Handle;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

如果您希望控制颜色和大小,那么最明显的选择是创建自己的对话框作为TForm后代.