Einzelnen Beitrag anzeigen

Simo

Registriert seit: 28. Apr 2014
51 Beiträge
 
#23

AW: Farbe zur Laufzeit verändern?

  Alt 3. Jun 2014, 15:41
Delphi-Quellcode:
unit Panel;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ImgList;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure Panel1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
  //procedure FormCreate(Sender: TObject);
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.Panel1Click(Sender: TObject);
const
  bgcolor = $00FF0000; //$00FFDDEE;
  linecolor = $00FFFFFF; //$00554366;
var
  img: array of TImage;
  reg: hrgn;
  i: Integer;
begin
  for i := 0 to ComponentCount - 1 do
  begin
    if Components[i].ClassName = 'TPanelthen
    begin
      setlength(img, Length(img) + 1);
      img[i] := TImage.Create(Self);
      img[i].Width := (Components[i] as TPanel).Width;
      img[i].Height := (Components[i] as TPanel).Height;
      img[i].Parent := (Components[i] as TPanel);
      img[i].Canvas.Brush.Color :=bgcolor;
      img[i].Canvas.pen.Color := bgcolor;
      img[i].Canvas.Rectangle(0,0,img[i].Width, img[i].Height);
      img[i].Canvas.pen.Color :=linecolor;
      img[i].Canvas.RoundRect(5,5,img[i].Width - 5,img[i].Height - 5,20,20);
      reg := CreateRoundRectRgn(0,0,(Components[i] as TPanel).Width,
        (Components[i] as TPanel).Height, 20,20);
      setwindowrgn((Components[i] as TPanel).Handle, reg, True);
      deleteobject(reg);
    end;
  end;
end;

end.
Wenn man drauf klickt dann wird das Panel einfach blau..
Ich möchte es genau programmieren wie im Anhang -(

??

Geändert von Simo ( 3. Jun 2014 um 15:55 Uhr)
  Mit Zitat antworten Zitat