AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit TBitmap property

Ein Thema von .chicken · begonnen am 1. Mai 2007 · letzter Beitrag vom 1. Mai 2007
 
.chicken

Registriert seit: 5. Dez 2006
459 Beiträge
 
#1

Problem mit TBitmap property

  Alt 1. Mai 2007, 18:17
Also ich versuche gerade mir eine Button Komponente zu programmieren.
Dabei habe ich bisher folgenden Ansatz!
Delphi-Quellcode:
unit GraphicButton;

interface

uses
  SysUtils, Classes, Controls, Graphics;

type
  TGraphicButton = class(TGraphicControl)
  private
    FBild: TBitmap;
    FBildClick: TBitmap;
    procedure SetBild(Value: TBitmap);
    procedure SetBildClick(Value: TBitmap);
  protected
    procedure Paint; Override;
    procedure Click;
  public
    property Canvas;
    constructor Create(AOwner: TComponent);
  published
    property Caption;
    property Color;
    property Bild: TBitmap read FBild write SetBild;
    property BildClick: TBitmap read FBildClick write SetBildClick;
    property Font;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Eigene', [TGraphicButton]);
end;

constructor TGraphicButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FBild := TBitmap.Create;
  FBildClick := TBitmap.Create;
end;

procedure TGraphicButton.Paint;
begin
  inherited;
  if Font <> nil then
    Canvas.Font := Font;
  if csDesigning in ComponentState then
  begin
    Canvas.Brush.Style := bsClear;
    Canvas.Pen.Style := psDashDot;
    Canvas.Rectangle(0, 0, width, height);
    Canvas.TextOut((width - Canvas.TextWidth(Caption)) div 2,(height - Canvas.TextHeight(Caption)) div 2, Caption);
  end
  else
  begin
    Canvas.Brush.Style := bsSolid;
    Canvas.Pen.Style := psSolid;
    Canvas.Brush.Color := Color;
    Canvas.Rectangle(0, 0, width, height);
    if Assigned(FBild) then
      Canvas.Draw(0, 0, FBild);
    Canvas.Brush.Style := bsClear;
    Canvas.TextOut((width - Canvas.TextWidth(Caption)) div 2,(height - Canvas.TextHeight(Caption)) div 2, Caption);
  end;
end;

procedure TGraphicButton.Click;
begin

end;

procedure TGraphicButton.SetBild(Value: TBitmap);
begin
  FBild.Assign(Value);
  Repaint;
end;

procedure TGraphicButton.SetBildClick(Value: TBitmap);
begin
  FBildClick.Assign(Value);
  Repaint;
end;

end.
Mein Problem: Ich muss immer bevor ich der Bild property ein Bitmap zuweisen will, noch ein Bild := TBitmap.Create aufrufen!
Hatte das auch schonmal im Constructor von TGraphicButton stehen, aber das hat trotzdem nicht funktioniert!
Was muss ich ändern?
  Mit Zitat antworten Zitat
 


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 18:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz