Einzelnen Beitrag anzeigen

ReDoX
(Gast)

n/a Beiträge
 
#4

Re: Farbe von showmessage ändern

  Alt 14. Feb 2005, 00:18
Ich habe mich hingesetzt und eine procedure geschrieben die genau das macht was ich brauche.
Sie heißt CustumMessage und passt sich dynamisch an die länge des Textes an.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, XPMan, ColorGrd;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ColorGrid1: TColorGrid;
    XPManifest1: TXPManifest;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure MessageButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
Form1: TForm1;
  MessageForm : Tform;
implementation

{$R *.dfm}

procedure CustomMessage(Text: string; FormColor, LabelColor: TColor);
var
  Messagelabel: TLabel;
  MessageButton: TButton;
begin
  MessageForm := TForm.Create(nil);
  Messagelabel := TLabel.Create(nil);
  MessageButton := TButton.Create(nil);

  with MessageForm do
   begin
    Color := FormColor;
    Caption := application.Title;
    SetBounds((Screen.Width - MessageForm.Width) div
     2, (Screen.Height - MessageForm.Height) div 2,MessageForm.Width,
      MessageForm.Height);
    BorderIcons := [biSystemMenu];
    BorderStyle := bsdialog;
    Height := 110;
   end;


  with Messagelabel do
   begin
    Caption := Text;
    Font.Color := LabelColor;
    Parent := MessageForm;
    Top := 15;
   end;

  with MessageButton do
   begin
    Caption := 'OK';
    Parent := MessageForm;
    Top := 40;
    OnClick := Form1.MessageButtonClick;
   end;

  MessageForm.Width := 75 + MessageLabel.Width;
  MessageButton.Left := MessageForm.Width div 2 - Messagebutton.Width div 2;
  MessageLabel.Left := MessageForm.Width div 2 - MessageLabel.Width div 2;
  MessageForm.ShowModal;
  FreeAndNil(MessageForm);
end;

procedure TForm1.MessageButtonClick(Sender: TObject);
begin
  MessageForm.ModalResult := 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CustomMessage(edit1.text,ColorGrid1.ForegroundColor,ColorGrid1.BackgroundColor);
end;

end.
Ich hoffe jemand kann sie gebrauchen!
Mfg ReDoX
  Mit Zitat antworten Zitat