Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tab control with textured background

Posted on 1998-07-03
3
Medium Priority
?
356 Views
Last Modified: 2010-04-04
I need a tab control with textured background (PageControl) - where can I find such a component or how to make a  textured tab control?
0
Comment
Question by:bengore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 600 total points
ID: 1357091
You should derivce a new TTabSheet control.

Here is a sample on how to do it:


*** start of code ***
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ExtCtrls;

type
  TMapTabSheet = class(TTabSheet)
  private
    FPicture : TImage;
    procedure WMPaint(var msg : TWMPaint); message WM_PAINt;
  protected
  public
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
  published
    property BackGround : TImage read FPicture write FPicture;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FControl : TPageControl;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

constructor TMapTabSheet.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FPicture:=TImage.Create(Self);
end;

destructor TMapTabSheet.Destroy;
begin
  FPicture.Free;
  inherited Destroy;
end;

procedure TMapTabSheet.WMPaint(var msg : TWMPaint);
var
  Canvas : TCanvas;
  i,j : Integer;
begin
  inherited;
  Canvas := TCanvas.Create;
  Canvas.Handle := GetDC(Handle);
  with Canvas do begin
    for i:=0 to Width div FPicture.Picture.Width do
      for j:=0 to Height div FPicture.Picture.Height do
        Draw(i*FPicture.Picture.Width,j*FPicture.Picture.Height,FPicture.Picture.Bitmap);
  end;
  Canvas.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FControl := TPageControl.Create(Self);
  with FControl do begin
    Parent := Self;
    Align := alClient;
    with TMapTabSheet.Create(Self) do begin
      PageControl := FControl;
      Caption := 'One';
      BackGround.Picture.LoadFromFile('c:\program files\borland\delphi 3\images\splash\256color\finance.bmp');
    end;
    with TMapTabSheet.Create(Self) do begin
      PageControl := FControl;
      Caption := 'Two';
      BackGround.Picture.LoadFromFile('c:\program files\borland\delphi 3\images\splash\256color\shipping.bmp');
    end;
  end;
end;

end.

*** end of code ***

Regards Jacco.
0
 

Author Comment

by:bengore
ID: 1357092
Nice solution. How to make a TMapPageControl component of this?
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1357093
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',[TMapPageControl]);
  RegisterComponentEditor(TMapPageControl,TMapPageControlEditor);
  RegisterComponentEditor(TMapTabSheet,TMapPageControlEditor);
  RegisterNoIcon([TMapTabSheet]);
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*FPicture.Height,FPicture.Bitmap);
      end;
      Canvas.Free;
    end;
  end;
end;

// TMapPageControl

function TMapPageControl.GetMapTabSheet(Index : Integer) : TMapTabSheet;
begin
  Result := TMapTabSheet(inherited Pages[Index]);
end;

// TMapPageControlEditor

function TMapPageControlEditor.GetVerbCount : Integer;
begin
  Result := 3;
end;

function TMapPageControlEditor.GetVerb(i : Integer) : String;
begin
  case i of
    0 : Result := 'New page';
    1 : Result := 'Next page';
    2 : Result := 'Previous page';
  end;
end;

procedure TMapPageControlEditor.ExecuteVerb(i : Integer);
var
  MapTabSheet : TMapTabSheet;
  MapPageControl : TMapPageControl;
  sName : String;
  iName : Integer;
begin
  if Component is TMapTabSheet then
    MapPageControl := TMapPageControl(TMapTabSheet(Component).PageControl)
  else
    MapPageControl := TMapPageControl(Component);
  case i of
    0 : begin
      MapTabSheet := TMapTabSheet.Create(Component.Owner);
      sName := 'TabSheet';
      iName := 1;
      while MapPageControl.Owner.FindComponent(sName+IntToStr(iName))<>nil do
        Inc(iName);
      MapTabSheet.Name:=sName + IntToStr(iName);
      MapTabSheet.PageControl := MapPageControl;
    end;
    1 : TMapPageControl(Component).SelectNextPage(True);
    2 : TMapPageControl(Component).SelectNextPage(False);
  end;
end;

initialization
  RegisterClasses([TMapTabSheet]);
end.
*** end of code ***
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question