0

I have a PageControl with the TabPosition set to "tpLeft". You notice when you set that property the caption of the tabs becomes Vertical too, I but i want these captions to appear in a normal horizontal way, tried changing the TabHeight, but it only got wider and the test still appears Vertical.

How can i fix that.

Using DELPHI XE5

update: This code works(Thank to 'Ken White'):

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  I: Integer;
  PageControl: TPageControl;
  TextFormat: TTextFormat;
  Text: string;
  TextRect: TRect;
begin
  PageControl := Control as TPageControl;

  Text := PageControl.Pages[TabIndex].Caption;

  for I := Length(Text) - 1 downto 1 do
  begin
    Text := Copy(Text, 1, I) + Copy(Text, I+1, MaxInt);
  end;

  TextRect := Rect;
  TextRect.Left := TextRect.Left + 5;
  TextRect.Top := TextRect.Top + 3;

  TextFormat := [tfCenter];

  PageControl.Canvas.TextRect(
    TextRect,
    Text,
    TextFormat
    );
end;

but is this the "right way" to do it, are there any other better methods?

Ouerghi Yassine
  • 1,835
  • 7
  • 43
  • 72
  • Owner-draw the tabs (draw them yourself), and rotate the font. – Ken White Nov 23 '13 at 01:20
  • How can i rotate the font? – Ouerghi Yassine Nov 23 '13 at 01:22
  • You want that text to be horizontal, don't you ? If so, you don't need to rotate the font. – TLama Nov 23 '13 at 01:23
  • 1
    Did you try searching for anything based on my comment? Put some effort into finding a solution, instead of just asking here. I've given you a topic to start researching. – Ken White Nov 23 '13 at 01:23
  • @TLama: Yes, you do. :-) The font (by default, when the tabs are on the left) rotates 90 degrees CCW (vertical, bottom to top text); to make it horizontal, you'd need to rotate it back CW the same amount. – Ken White Nov 23 '13 at 01:26
  • @Ken, I was thinking of [`this orientation`](http://i.imgur.com/9572QFB.png). – TLama Nov 23 '13 at 01:29
  • @TLama and thats what i want to do ... – Ouerghi Yassine Nov 23 '13 at 01:29
  • Then you don't need to rotate. Here's an [`example code`](http://pastebin.com/Je73Dcny) using hardcoded positions. – TLama Nov 23 '13 at 01:35
  • 2
    @TLama: Nicely done (code in the link), but I don't like the hard-coded positions. You're right about the rotation, though; it appears from your example that it's not needed. :-) The code you posted might work though, if you knew in advance what tabs were needed. You could keep them in a list/array, iterate through in the form's constructor and calculate the TextWidth and TextHeight of the strings based on the font, and use those values at runtime to set the tab width and height values instead of the hardcoded ones. You might want to post an answer instead. – Ken White Nov 23 '13 at 01:39
  • 1
    @TLama thanks, i've change: `Rect.Left + TPageControl(Control).TabHeight div 2` – Ouerghi Yassine Nov 23 '13 at 01:42
  • 1
    The `for` loop is useless. The final `Text` after the loop is finished is identical to the original `Text` before the loop started. So you can get rid of the loop completely. – Remy Lebeau Nov 23 '13 at 02:22
  • @TLama Unfortunately this does not work when a VCL Style is active. – user1580348 Aug 08 '15 at 19:43
  • @user1580348, I'm not surprised, to be honest. VCL Styles are a different beast, full of style hooks. I think the best will be asking a separate question about the same topic, but for the VCL Styles specifically. Just, if I could recommend, include the code that you've tried, an images of the current and desired result, as well as the specific version tag(s), and I bet you will soon get an answer from someone experienced in VCL Styles. – TLama Aug 08 '15 at 20:11

0 Answers0