TPageControl ownerdraw missing


2005-12-21 10:53:41 AM
kylix2
Hello, I just found out how to put an image on the tab but the problem is I
put it on the OnChange Event, My problem now is how will i put this during
the creation since I tried it it wont work. Also, I tried three tabs but the
background images covers only two tabs. Is this a bug? here is my code.
unit Unit1;
interface
uses
SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms,
QDialogs, QStdCtrls, QComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Button1: TButton;
TabSheet3: TTabSheet;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure PageControl1Changing(Sender: TObject;
var AllowChange: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
TPageControlEx = class(TPageControl)
public
property Bitmap;
property OwnerDraw;
end;
var
Form1: TForm1;
Background : TBitmap;
implementation
{$R *.xfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
Background := TBitmap.Create;
// could load bitmap from a resource here
Background.Loadfromfile('back.bmp');
TPageControlEx(PageControl1).OwnerDraw := True;
// subclass the tabsheets, store old window proc in GWL_USERDATA
// field of window structure
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Background.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// close;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
pagecontrol1.Brush.Bitmap := Background;
pagecontrol1.Brush.Bitmap.FreeImage;
TPageControlEx(pagecontrol1).Bitmap := Background;
TPageControlEx(pagecontrol1).Bitmap.FreeImage;
end;
procedure TForm1.PageControl1Changing(Sender: TObject;
var AllowChange: Boolean);
begin
(sender as Tpagecontrol).Canvas.Brush.Bitmap := Background;
(sender as Tpagecontrol).Canvas.Brush.Bitmap.FreeImage;
end;
end.
Any ideas?
Thanks in advance.