组件问题!!急!
这里是我写的程序,是一个由label和bitbtn组成的组件,上半是bitbtn,下半是label!
unit Mywin5;
interface
uses
Windows,Messages,Graphics,Forms,Dialogs,StdCtrls,Buttons,SysUtils, Classes, Controls,Variants;
type
TMywin4 = class(TWinControl)
private
{ Private declarations }
FBitbtn:TBitBtn;
FLabel:TLabel;
//FCanvas: TCanvas;
FGlyph: TBitmap;
//procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
protected
{ Protected declarations }
procedure WMSize(var Message:TWMSize);message WM_SIZE;
procedure SetText(Value:String);
function GetText:String;
procedure SetFont(Value:TFont);
function GetFont:TFont;
procedure SetCaption(Value:String);
function GetCaption:String;
procedure SetOnButtonClick(Value:TNotifyEvent);
function GetOnButtonClick:TNotifyEvent;
procedure SetGlyph(Value: TBitmap);
function GetGlyph: TBitmap;
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property Text:String read GetText write SetText;
property Font:TFont read GetFont write SetFont;
property Caption:String read GetCaption write SetCaption;
property OnButtonClick:TNotifyEvent read GetOnButtonClick write SetOnButtonClick;
property Enabled;
property Glyph: TBitmap read GetGlyph write SetGlyph;
end;
procedure Register;
implementation
procedure TMywin4.WMSize(var Message:TWMSize);
begin
inherited ;
FLabel.Width := Message.Width;
//FLabel.Height:= Int((Message.Height)/2);
FBitBtn.Width := Message.Width;
//TBitBtn.Height:= (Message.Height)/2;
end;
//Fpanel := Message.Height;
constructor TMywin4.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FBitBtn :=TBitbtn.Create(Self);
FBitBtn.Parent := Self;
FBitBtn.Left:=Self.Left+Self.Width;
FBitBtn.Top:=Self.Top;
FLabel:=TLabel.Create(Self);
FLabel.Parent:=Self;
FLabel.Left:=Self.Left;
FLabel.Height:=FBitbtn.Height;
FLabel.Top:=Self.Top-FBitBtn.Height;
Width:=FLabel.Width;
Height:=FLabel.Height+FBitbtn.Height;
end;
procedure TMywin4.SetText(Value:String);
begin
FLabel.Caption:=Value;
end;
function TMywin4.GetText:String;
begin
Result:=FLabel.Caption;
end;
procedure TMywin4.SetCaption(Value:String);
begin
FBitbtn.caption:=Value;
end;
function TMywin4.Getcaption:String;
begin
Result:=FBitbtn.Caption;
end;
procedure TMywin4.SetFont(Value:TFont);
begin
if Assigned(Flabel.Font) then
FLabel.Font.Assign(Value);
FBitbtn.Font.Assign(Value);
end;
function TMywin4.GetFont:TFont;
begin
Result:=FLabel.Font;
end;
procedure TMywin4.SetOnButtonClick(Value:TNotifyEvent);
begin
FBitbtn.Onclick:=Value;
end;
function TMywin4.GetOnButtonClick:TNotifyEvent;
begin
Result:=FBitbtn.onclick;
end;
procedure TMywin4.SetGlyph(Value: TBitmap);
begin
if FGlyph<>Value then
begin
FGlyph.Assign(Value);
end;
end;
function TMywin4.GetGlyph:TBitmap;
begin
Result:=FGlyph;
end;
destructor TMywin4.Destroy;
begin
FBitBtn.Free;
FLabel.Free;
FGlyph.Free;
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Samples', [TMywin4]);
end;
end.
问题1:是在object inspector里面选glyph时后,bitbtn 没有显示。运行出现
project project1.exe raise exception class EreadError with message 'Invalid property path'.
问题2:我不想设死控件高度!我想控制bitbtn和label一样搞,各占高度的一半,应该怎么改?