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

x
?
Solved

Add Close button to Each Tab

Posted on 2004-09-23
11
Medium Priority
?
5,863 Views
Last Modified: 2009-08-11
HELLO,

i need to add a close button to each tab (TPageControl ot TTabControl)  so i used the drawtab event

// i is an imagelist
i.Draw(tabcontrol1.Canvas,Rect.Right -20,Rect.Top +2,0);

but this seems to remove all the 3d and xp style painting, anyway to make the
control continue the default painting after this line?

Thanks
Yehia
0
Comment
Question by:yehiaeg
[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
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12134709
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  Icon : TIcon;
begin
  inherited;
  Icon := TIcon.Create;
  with Control.Canvas do
    begin
      Pen.Color := clBlue;
      ImageList1.GetIcon(0, Icon);
      Draw(Rect.Right - 20, Rect.Top + 2, Icon);
    end;
end;
0
 

Author Comment

by:yehiaeg
ID: 12134949
na, didn't work, did u try it?
0
 

Author Comment

by:yehiaeg
ID: 12134971
still add the image but the xp style and default painting are gone
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12135558
You can use TMS TAdvPageControl v.1.2 from TMS Software, that has a built-in close button property for each tab.
It's fully functional, however, without source. See:
 - http://torry.net/pages.php?id=164
 - http://www.tmssoftware.com/
0
 

Author Comment

by:yehiaeg
ID: 12135644
don't really want to use 3rd parties product, anyother solution?
0
 
LVL 2

Expert Comment

by:cqhall
ID: 12136097
You could add an imagelist containing the image of a button, set the imagelist property of the pagecontrol to the imagelist and set the imageindex of each tab to the button's index. This approach ensures that you get the default drawing behaviour and reserves space for the "buttons".

Whether you use an imagelist or draw the button yourself, you'll need to determine when the "button" is clicked.  The mousedown of the pagecontrol will see clicks within the tabs and give you a and y coordinates, but you'l need to determine if the mouseclick corresponds to the position of a "button".  If the position of the tabs stays contant (no scrolling or multirow), you could store the limits for each button in your code.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12136314
>> na, didn't work, did u try it?
on Windows 2000, I don't have XP installed. :}
0
 

Author Comment

by:yehiaeg
ID: 12137942
i added the imagelist and it worked ok, but is there anyway to put the image after the text and not before it?
0
 
LVL 2

Accepted Solution

by:
cqhall earned 375 total points
ID: 12140023
Sorry, I couldn't find a way to reverse the image and caption.  However, I did find the pagecontrol's tabrect(i) property you can use to compare with the mousedown coordinates to see where the mouse was clicked relative to the "buttons".

When I clicked on the "button" on the first tab of a test pagecontrol, the results were x: 12 y: 10

When I looped through the tabrects (0 to pagecontrol.pagecount-1) I got the following values:

left: 2 top: 2 right: 89 bottom: 21
left: 89 top: 2 right: 176 bottom: 21
left: 176 top: 2 right: 263 bottom: 21
left: 263 top: 2 right: 350 bottom: 21


procedure TForm1.Button1Click(Sender: TObject);
var
 i: integer;
 rect: tRect;
begin
 memo1.Clear;
 for i:=0 to pagecontrol1.PageCount-1 do
 begin
  rect:=pagecontrol1.TabRect(i);
  memo1.lines.Add('left: '+inttostr(rect.Left)
                    +' top: '+inttostr(rect.Top)
                    +' right: '+inttostr(rect.Right)
                    +' bottom: '+inttostr(rect.Bottom));
 end;
end;

procedure TForm1.PageControl1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 memo1.lines.Add('x: '+inttostr(x)+' y: '+inttostr(y));
end;


Chuck
0
 
LVL 3

Expert Comment

by:Sabre
ID: 12147306
Maybe i read the question wrong but.....

why not create buttons and assign the parent of them to the PageControl?  That way you'd have all of the events, properties of the buttons - and could set the Onclick event to the same procedure for all of the buttons.
0
 
LVL 2

Expert Comment

by:cula99
ID: 12248140
{pas}
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  Button1.Parent:=PageControl1.ActivePage;
end;

end.


{dfm}

object Form1: TForm1
  Left = 244
  Top = 176
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 0
    Top = 0
    Width = 862
    Height = 613
    ActivePage = TabSheet1
    Align = alClient
    TabOrder = 0
    OnChange = PageControl1Change
    object TabSheet1: TTabSheet
      Caption = 'TabSheet1'
      object Button1: TButton
        Left = 760
        Top = 544
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'TabSheet2'
      ImageIndex = 1
    end
    object TabSheet3: TTabSheet
      Caption = 'TabSheet3'
      ImageIndex = 2
    end
  end
end
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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