AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Farbe zur Laufzeit verändern?

Ein Thema von Simo · begonnen am 3. Jun 2014 · letzter Beitrag vom 10. Jun 2014
 
Simo

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

AW: Farbe zur Laufzeit verändern?

  Alt 4. Jun 2014, 08:45
Ich hab's versucht.. ist aber leider nicht was ich will..

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
  TPanel = class(Vcl.ExtCtrls.TPanel)
    private { Private-Deklarationen }
    FOnPaint: TNotifyEvent;
    protected { Protected-Deklarationen }
    procedure Paint; override; public
    { Public-Deklarationen }
    property Canvas;
    published { Published-Deklarationen }
    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
    end;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure OnPanel1Paint(Sender: TOBject);
  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(5,5,img[i].Width, img[i].Height);
      img[i].Canvas.pen.Color :=linecolor;
      img[i].Canvas.RoundRect(0,0,img[i].Width - 50,img[i].Height - 5,20,20);
      reg := CreateRoundRectRgn(0,0,(Components[i] as TPanel).Width,
        (Components[i] as TPanel).Height, 0,0);
      setwindowrgn((Components[i] as TPanel).Handle, reg, True);
      deleteobject(reg);
    end;
  end;
end;



procedure TPanel.Paint;
begin
inherited;
  if assigned(fOnPaint) then
  fOnPaint(Self);
  end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Panel1.OnPaint := OnPanel1Paint;
end;

procedure TForm1.OnPanel1Paint(Sender: TOBject);
var r: Trect;
begin
  r := Panel1.ClientRect;
  InflateRect(r, -2, -2);
  With Panel1 do
  begin
  Canvas.Brush.Color :=$CD0000;//clWindow;
  Canvas.RoundRect(r.Left, r.Top, r.Right, r.Bottom, 20, 20);
  Canvas.Brush.Color := Panel1.Color;
  Canvas.Draw(5, 5, Application.Icon);
  Canvas.Brush.Color := $FFFFE0;
  Canvas.RoundRect(r.Left, r.Top, r.Right-120, r.Bottom, 30, 30);
  Canvas.Brush.Color:=Panel1.Color;
  Canvas.Draw(5, 5, Application.Icon);

  end;
end;

end.
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:04 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz