Pisanie komponentów C.D.

0

Piszę komponent i chciałbym aby można było umieścić bitmapę w zasobach programu, jak ma to miejsce przy komponencie TImage. Dałem coś takiego:

property Glyph : TBitmap read obrazek write obrazek;

I owszem, jest okienko do ładowania bitmapy, tylko jak załaduję i kliknę na ok, to całe delphi się zamyka :(. Jak to zrobić?---------------------------
Delphi 6

Pozdrówka

0

podaj kodik ktory otwiera bitmapę :)

0

Otwiera, czyli...? Wydawało mi się, że otwiera delphi, a komponent tylko z tego korzysta. Najlepiej dam tu cały kod:

unit ModernButton;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, graphics, ExtCtrls;

type
TModernButton = class(TGRaphicControl)
private
FOnclick:TNotifyEvent;
protected
procedure Paint; override;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure WMLBUTTONDOWN(var Msg: TMessage); message WM_LBUTTONDOWN;
procedure WMLBUTTONUP(var Msg: TMessage); message WM_LBUTTONUP;

public
obrazek:tbitmap;
state:integer;
glyph:TImage;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Glyph : TBitmap read obrazek write obrazek;

property OnClick : TNotifyEvent read Fonclick write Fonclick;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Modern', [TModernButton]);
end;

{ TModernButton }

procedure TModernButton.CMMouseEnter(var Msg: TMessage);
begin
state:=1;
paint;
end;

procedure TModernButton.CMMouseLeave(var Msg: TMessage);
begin
state:=0;
paint;
end;

constructor TModernButton.Create(AOwner: TComponent);
begin
inherited;
obrazek:=tbitmap.create;
end;

destructor TModernButton.Destroy;
begin
obrazek.free;
image.Free;
inherited;
end;

procedure TModernButton.Paint;
begin
inherited;

if state=0 then
begin
canvas.Pen.Color:=14609903;
canvas.Brush.Color:=14609903;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2, height div 2-obrazek.Height div 2, obrazek);
end;

if state=1 then
begin
canvas.Pen.Color:=12937777;
canvas.Brush.Color:=15651521;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2-1, height div 2-obrazek.Height div 2-1, obrazek);
end;

if state=2 then
begin
canvas.Pen.Color:=12937777;
canvas.Brush.Color:=15651521;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2+1, height div 2-obrazek.Height div 2+1, obrazek);
end;

end;

procedure TModernButton.WMLBUTTONDOWN(var Msg: TMessage);
begin
state:=2;
paint;
end;

procedure TModernButton.WMLBUTTONUP(var Msg: TMessage);
begin
state:=1;
paint;

if Assigned(fonclick) then
onclick(Self);
end;

end.

Delphi 6

Pozdrówka

0

Otwiera, czyli...? Wydawało mi się, że otwiera delphi, a komponent tylko z tego korzysta. Najlepiej dam tu cały kod:

unit ModernButton;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, graphics, ExtCtrls;

type
TModernButton = class(TGRaphicControl)
private
FOnclick:TNotifyEvent;
protected
procedure Paint; override;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure WMLBUTTONDOWN(var Msg: TMessage); message WM_LBUTTONDOWN;
procedure WMLBUTTONUP(var Msg: TMessage); message WM_LBUTTONUP;

public
obrazek:tbitmap;
state:integer;
glyph:TImage;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Glyph : TBitmap read obrazek write obrazek;

property OnClick : TNotifyEvent read Fonclick write Fonclick;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Modern', [TModernButton]);
end;

{ TModernButton }

procedure TModernButton.CMMouseEnter(var Msg: TMessage);
begin
state:=1;
paint;
end;

procedure TModernButton.CMMouseLeave(var Msg: TMessage);
begin
state:=0;
paint;
end;

constructor TModernButton.Create(AOwner: TComponent);
begin
inherited;
obrazek:=tbitmap.create;
end;

destructor TModernButton.Destroy;
begin
obrazek.free;
image.Free;
inherited;
end;

procedure TModernButton.Paint;
begin
inherited;

if state=0 then
begin
canvas.Pen.Color:=14609903;
canvas.Brush.Color:=14609903;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2, height div 2-obrazek.Height div 2, obrazek);
end;

if state=1 then
begin
canvas.Pen.Color:=12937777;
canvas.Brush.Color:=15651521;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2-1, height div 2-obrazek.Height div 2-1, obrazek);
end;

if state=2 then
begin
canvas.Pen.Color:=12937777;
canvas.Brush.Color:=15651521;
Canvas.Rectangle(0, 0, width, height);
if not obrazek.Empty then
canvas.Draw(width div 2-obrazek.Width div 2+1, height div 2-obrazek.Height div 2+1, obrazek);
end;

end;

procedure TModernButton.WMLBUTTONDOWN(var Msg: TMessage);
begin
state:=2;
paint;
end;

procedure TModernButton.WMLBUTTONUP(var Msg: TMessage);
begin
state:=1;
paint;

if Assigned(fonclick) then
onclick(Self);
end;

end.

Delphi 6

Pozdrówka

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0