Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Size of tab for pagecontrol

1,455 views
Skip to first unread message

Mark Smits

unread,
Jul 15, 2002, 12:05:25 PM7/15/02
to
I am using OnDrawTab of the TPageControl to do some custom drawing of
the tab. Unfortunately the size of the tab seems to be controlled by
the size of the font of the TPageControl and the size of the Caption
of the TTabSheet.

Is there any other way to influence the size of the tab ?


Kind regards,
Mark Smits
--
Sm...@Com-Unit.com

Com-Unit BV, The Netherlands.
The makers of Spider-Road®.

Peter Below (TeamB)

unread,
Jul 15, 2002, 2:22:19 PM7/15/02
to
In article <shr5ju8s6b13fb2ci...@4ax.com>, Mark Smits
wrote:

> I am using OnDrawTab of the TPageControl to do some custom drawing of
> the tab. Unfortunately the size of the tab seems to be controlled by
> the size of the font of the TPageControl and the size of the Caption
> of the TTabSheet.
>
> Is there any other way to influence the size of the tab ?

There is. Look at the entry for TCM_SETITEMSIZE in win32.hlp.


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Mark Smits

unread,
Jul 16, 2002, 8:17:56 AM7/16/02
to
On Mon, 15 Jul 2002 20:22:19 +0200, "Peter Below (TeamB)" wrote:

>There is. Look at the entry for TCM_SETITEMSIZE in win32.hlp.

Thanks. Been trying it, but the effect is not what I expected. I am
using the OnShow event, which seems to be the right place, of the
tabsheet to do this:

SendMessage(PageControl1.Handle, TCM_SETITEMSIZE, 0,
MAKELPARAM(100,100));

It looks like it's reserving space as specified, but still the tab
size itself takes the old dimensions. I am getting drawn something
like this:

_____
| Tab |
|
|
|
| |
| |
| |
------------------------------

where it should be

_____________
| Tab |
| |
| |
| ----------------
| |
| |
| |
------------------------------

In other words: Tab is still as small as the fontsize and captionsize
allow it to be. It is not the specified width. There seems to be some
reserved space of the new dimensions (concluded that because of the
incomplete right line). Not all the lines are drawn. Missing the right
one of the tab and the top of the page.

Further more, my drawing is not displayed in that reserved region. I
see some drawing on the left (some kind of border idea) and the
drawing in the (small) tab, but that's it.

Any help appreciated. I've put my testcase source below my sig.

Kind regards,
Mark Smits
--
Sm...@Com-Unit.com

Com-Unit BV, The Netherlands.
The makers of Spider-Road®.


procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
CenterText, CenterRect: Integer;
TextLeft, TextTop: Integer;
RectTop, RectMiddle, RectBottom: TRect;
begin
try
RectTop := Rect;
RectMiddle := Rect;
RectBottom := Rect;
RectTop.Bottom := RectTop.Top + ((Rect.Bottom - Rect.Top) div 3);
RectMiddle.Top := RectTop.Bottom + 1;
RectMiddle.Bottom := RectMiddle.Top + ((Rect.Bottom - Rect.Top)
div 3);
RectBottom.Top := RectMiddle.Bottom + 1;
Control.Canvas.Brush.Color := clRed;
Control.Canvas.FillRect(RectTop);
Control.Canvas.Brush.Color := clWhite;
Control.Canvas.FillRect(RectMiddle);
Control.Canvas.Brush.Color := clBlue;
Control.Canvas.FillRect(RectBottom);
Control.Canvas.Brush.Style := bsClear;
Control.Canvas.Font.Color := clBlack;
Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsBold];
Control.Canvas.Font.Size := RectMiddle.Bottom - RectMiddle.Top -
(2 * 3);
CenterText := Control.Canvas.TextWidth(TabSheet1.Caption) div 2;
CenterRect := (Rect.Right - Rect.Left) div 2;
TextLeft := Rect.Left + (CenterRect - CenterText);
CenterText := Control.Canvas.TextHeight(TabSheet1.Caption) div 2;
CenterRect := (Rect.Bottom - Rect.Top) div 2;
TextTop := Rect.Top + (CenterRect - CenterText);
Control.Canvas.TextOut(TextLeft, TextTop, TabSheet1.Caption);
finally
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if not PageControl1.OwnerDraw then begin
TabSheet1.Caption := 'THE NETHERLANDS';
PageControl1.OwnerDraw := True;
end else begin
TabSheet1.Caption := 'Tab';
PageControl1.OwnerDraw := False;
end;
end;

procedure TForm1.TabSheet1Show(Sender: TObject);
var
Result: Integer;
i: Integer;
begin
if PageControl1.OwnerDraw then begin
Result := SendMessage(PageControl1.Handle, TCM_SETITEMSIZE, 0,
MAKELPARAM(200,200));
end;
end;

Peter Below (TeamB)

unread,
Jul 16, 2002, 2:09:09 PM7/16/02
to
In article <f218ju48tsjkmnuqo...@4ax.com>, Mark Smits
wrote:
> >There is. Look at the entry for TCM_SETITEMSIZE in win32.hlp.
>
> Thanks. Been trying it, but the effect is not what I expected. I am
> using the OnShow event, which seems to be the right place, of the
> tabsheet to do this:
>
> SendMessage(PageControl1.Handle, TCM_SETITEMSIZE, 0,
> MAKELPARAM(100,100));
>
> It looks like it's reserving space as specified, but still the tab
> size itself takes the old dimensions. I am getting drawn something
> like this:

I have never used this message but from the docs i suspect that it is
intended for the use with owner-drawn tabcontrols only, so *you* are
supposed to fill the reserved area with meaningful content, the default
drawing will still use the old standard size.

Mark Smits

unread,
Jul 17, 2002, 5:48:53 AM7/17/02
to
On Tue, 16 Jul 2002 20:09:09 +0200, "Peter Below (TeamB)"
<10011...@compuXXserve.com> wrote:

>I have never used this message but from the docs i suspect that it is
>intended for the use with owner-drawn tabcontrols only, so *you* are
>supposed to fill the reserved area with meaningful content, the default
>drawing will still use the old standard size.

If only my drawing would show up in that reserved area. But it isn't
and the "default" tab with its "default size" is still drawn
automatically. I think I must force a repaint in some way. If time
permits I will go through the VCL source and see what Borland is doing
when setting TabWidth/TabHeight.

Anyway, I am now using the TabHeight and TabWidth to control the size
of the Tabs. Not exactly what I need (I need varying widths not
depending on the TextWidth of the caption), but it will do for now.

Thanx for the help.

Chris Luck

unread,
Jul 17, 2002, 9:47:46 AM7/17/02
to
"Mark Smits" <Sm...@Com-Unit.com> wrote in message
news:ameajugqer2kbd6sj...@4ax.com...

> On Tue, 16 Jul 2002 20:09:09 +0200, "Peter Below (TeamB)"
> <10011...@compuXXserve.com> wrote:
>
> Anyway, I am now using the TabHeight and TabWidth to control the size
> of the Tabs. Not exactly what I need (I need varying widths not
> depending on the TextWidth of the caption), but it will do for now.

As a cheap n' chearful fudge you can extend the caption with spaces to
adjust tabwidth.


--
Regards,

Chris Luck.


0 new messages