bengore
asked on
Tab control with textured background
I need a tab control with textured background (PageControl) - where can I find such a component or how to make a textured tab control?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to derive a new class from TPageControl and a new TComponentEditor.
I show the code below.
The BackGround property changed from TImage to TPicture. And it needed a SetBackGround method for assigning.
The TMapPageControl only has an override of the property Pages and a GetMapTabSheet function. (It uses the inherited Pages property so you don't have to rewrite a lot of code).
Good luck
Don't you love component design !
Regards Jacco
Notes:
- Pay attention to the initialization section.
- RegisterNoIcon for the TMapTabSheet
- The component editor is Registered for both the TMapTabSheet and the TMapPageControl (so that the right mouse click works anywhere)
*** start of code ***
unit UMapPageControl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, DsgnIntf;
type
TMapTabSheet = class(TTabSheet)
private
FPicture : TPicture;
procedure WMPaint(var msg : TWMPaint); message WM_PAINt;
procedure SetBackGround(Value : TPicture);
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property BackGround : TPicture read FPicture write SetBackGround;
end;
TMapPageControl = class(TPageControl)
private
function GetMapTabSheet(Index : Integer) : TMapTabSheet;
public
property Pages[Index : Integer] : TMapTabSheet read GetMapTabSheet;
end;
TMapPageControlEditor = class(TComponentEditor)
public
function GetVerbCount : Integer; override;
function GetVerb(i : Integer) : String; override;
procedure ExecuteVerb(i : Integer); override;
end;
procedure Register;
implementation
// Register
procedure Register;
begin
RegisterComponents('Jacco' ,[TMapPage Control]);
RegisterComponentEditor(TM apPageCont rol,TMapPa geControlE ditor);
RegisterComponentEditor(TM apTabSheet ,TMapPageC ontrolEdit or);
RegisterNoIcon([TMapTabShe et]);
end;
// TMapTabSheet
constructor TMapTabSheet.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FPicture:=TPicture.Create;
end;
destructor TMapTabSheet.Destroy;
begin
FPicture.Free;
inherited Destroy;
end;
procedure TMapTabSheet.SetBackGround (Value: TPicture);
begin
FPicture.Assign(Value);
end;
procedure TMapTabSheet.WMPaint(var msg : TWMPaint);
var
Canvas : TCanvas;
i,j : Integer;
begin
inherited;
if Assigned(FPicture) then begin
if (FPicture.Width<>0) and (FPicture.Height<>0) then begin
Canvas := TCanvas.Create;
Canvas.Handle := GetDC(Handle);
with Canvas do begin
for i:=0 to Width div FPicture.Width do
for j:=0 to Height div FPicture.Height do
Draw(i*FPicture.Width,j*FP icture.Hei ght,FPictu re.Bitmap) ;
end;
Canvas.Free;
end;
end;
end;
// TMapPageControl
function TMapPageControl.GetMapTabS heet(Index : Integer) : TMapTabSheet;
begin
Result := TMapTabSheet(inherited Pages[Index]);
end;
// TMapPageControlEditor
function TMapPageControlEditor.GetV erbCount : Integer;
begin
Result := 3;
end;
function TMapPageControlEditor.GetV erb(i : Integer) : String;
begin
case i of
0 : Result := 'New page';
1 : Result := 'Next page';
2 : Result := 'Previous page';
end;
end;
procedure TMapPageControlEditor.Exec uteVerb(i : Integer);
var
MapTabSheet : TMapTabSheet;
MapPageControl : TMapPageControl;
sName : String;
iName : Integer;
begin
if Component is TMapTabSheet then
MapPageControl := TMapPageControl(TMapTabShe et(Compone nt).PageCo ntrol)
else
MapPageControl := TMapPageControl(Component) ;
case i of
0 : begin
MapTabSheet := TMapTabSheet.Create(Compon ent.Owner) ;
sName := 'TabSheet';
iName := 1;
while MapPageControl.Owner.FindC omponent(s Name+IntTo Str(iName) )<>nil do
Inc(iName);
MapTabSheet.Name:=sName + IntToStr(iName);
MapTabSheet.PageControl := MapPageControl;
end;
1 : TMapPageControl(Component) .SelectNex tPage(True );
2 : TMapPageControl(Component) .SelectNex tPage(Fals e);
end;
end;
initialization
RegisterClasses([TMapTabSh eet]);
end.
*** end of code ***
I show the code below.
The BackGround property changed from TImage to TPicture. And it needed a SetBackGround method for assigning.
The TMapPageControl only has an override of the property Pages and a GetMapTabSheet function. (It uses the inherited Pages property so you don't have to rewrite a lot of code).
Good luck
Don't you love component design !
Regards Jacco
Notes:
- Pay attention to the initialization section.
- RegisterNoIcon for the TMapTabSheet
- The component editor is Registered for both the TMapTabSheet and the TMapPageControl (so that the right mouse click works anywhere)
*** start of code ***
unit UMapPageControl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, DsgnIntf;
type
TMapTabSheet = class(TTabSheet)
private
FPicture : TPicture;
procedure WMPaint(var msg : TWMPaint); message WM_PAINt;
procedure SetBackGround(Value : TPicture);
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property BackGround : TPicture read FPicture write SetBackGround;
end;
TMapPageControl = class(TPageControl)
private
function GetMapTabSheet(Index : Integer) : TMapTabSheet;
public
property Pages[Index : Integer] : TMapTabSheet read GetMapTabSheet;
end;
TMapPageControlEditor = class(TComponentEditor)
public
function GetVerbCount : Integer; override;
function GetVerb(i : Integer) : String; override;
procedure ExecuteVerb(i : Integer); override;
end;
procedure Register;
implementation
// Register
procedure Register;
begin
RegisterComponents('Jacco'
RegisterComponentEditor(TM
RegisterComponentEditor(TM
RegisterNoIcon([TMapTabShe
end;
// TMapTabSheet
constructor TMapTabSheet.Create(AOwner
begin
inherited Create(AOwner);
FPicture:=TPicture.Create;
end;
destructor TMapTabSheet.Destroy;
begin
FPicture.Free;
inherited Destroy;
end;
procedure TMapTabSheet.SetBackGround
begin
FPicture.Assign(Value);
end;
procedure TMapTabSheet.WMPaint(var msg : TWMPaint);
var
Canvas : TCanvas;
i,j : Integer;
begin
inherited;
if Assigned(FPicture) then begin
if (FPicture.Width<>0) and (FPicture.Height<>0) then begin
Canvas := TCanvas.Create;
Canvas.Handle := GetDC(Handle);
with Canvas do begin
for i:=0 to Width div FPicture.Width do
for j:=0 to Height div FPicture.Height do
Draw(i*FPicture.Width,j*FP
end;
Canvas.Free;
end;
end;
end;
// TMapPageControl
function TMapPageControl.GetMapTabS
begin
Result := TMapTabSheet(inherited Pages[Index]);
end;
// TMapPageControlEditor
function TMapPageControlEditor.GetV
begin
Result := 3;
end;
function TMapPageControlEditor.GetV
begin
case i of
0 : Result := 'New page';
1 : Result := 'Next page';
2 : Result := 'Previous page';
end;
end;
procedure TMapPageControlEditor.Exec
var
MapTabSheet : TMapTabSheet;
MapPageControl : TMapPageControl;
sName : String;
iName : Integer;
begin
if Component is TMapTabSheet then
MapPageControl := TMapPageControl(TMapTabShe
else
MapPageControl := TMapPageControl(Component)
case i of
0 : begin
MapTabSheet := TMapTabSheet.Create(Compon
sName := 'TabSheet';
iName := 1;
while MapPageControl.Owner.FindC
Inc(iName);
MapTabSheet.Name:=sName + IntToStr(iName);
MapTabSheet.PageControl := MapPageControl;
end;
1 : TMapPageControl(Component)
2 : TMapPageControl(Component)
end;
end;
initialization
RegisterClasses([TMapTabSh
end.
*** end of code ***
ASKER