mazluta
mazluta

Reputation: 99

The caption of "flipped" on styled pagecontrol to RTL

I use Delphi 10.3, some styles (Of RAD only) I write right-to-left desktop applications. with "normal" widows.

The pagecontrol draw the tabsheet from left-to-right, like this

enter image description here

but I want the page control to paint itself from right-to-left, like this

enter image description here

for that, I use the code

procedure TMasterOfAllFrm.SetPageControlRightToLeft(PC : TPageControl);
const
  LVM_FIRST = $1000;
  LVM_GETHEADER = LVM_FIRST + 31;
var
  header: thandle;
begin
// START - to restore - open all lines
  header := SendMessage(PC.Handle, LVM_GETHEADER, 0, 0);
  SetWindowLong(header, GWL_EXSTYLE, GetWindowLong(header, GWL_EXSTYLE) or
    WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);

  SetWindowLong(PC.Handle, GWL_EXSTYLE, GetWindowLong(PC.Handle,
    GWL_EXSTYLE) or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
// END - to restore - open all lines
end;

it works fine, but when I use STYLE the caption of the tabsheet is "flipped as Mirror view", like this

enter image description here

how can I rotate that CAPTION, I tried to flip the font, remove the [sefont] from the pagecontrol, flip the string.... nada. no success.

Does someone have a better idea?

Upvotes: 1

Views: 233

Answers (1)

HMil
HMil

Reputation: 57

type
   TPageControl = class(ComCtrls.TPageControl)
   private
    tc : TTabControl;
    procedure tcChange(Sender : TObject);
   protected
     procedure loaded; override;
   end;

implementation

{$R *.dfm}

Procedure SetRTL(Control : TWinControl);
begin
  SetWindowLong (Control.Handle, GWL_EXSTYLE,
                 GetWindowLong (Control.Handle, GWL_EXSTYLE)  or
                 WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
  Control.invalidate;
end;



procedure TPageControl.loaded;
var i,j : integer;
begin
  inherited loaded;
  tc := TTabControl.Create(Self.Owner);
  tc.Parent := Parent;
  tc.Width := Width;
  tc.Height := height;
  tc.Top := Top;
  tc.Left := Left;
  tc.Align := Align;
  SetRTL(tc);
  Self.Parent := tc;
  Self.Align := alclient;
  Self.Style := tsFlatButtons;
  j := ActivePageIndex;
  for i := 0 to PageCount-1 do
    tc.Tabs.Add(Pages[i].Caption);
  tc.OnChange := tcChange;
  tc.OnResize := tcResize;
  tc.TabIndex := j;
end;


procedure TPageControl.tcResize(Sender : TObject);
var i : integer;
begin
 i := Self.ActivePageIndex;
 Self.ActivePageIndex := -1;
 Self.ActivePageIndex := i;
end;

procedure TPageControl.tcChange(Sender : TObject);
begin
 ActivePageIndex := tc.TabIndex;
end;

Then you have to MANUALLY hide the tabs of the TPageControl.

    PageControl1.Pages[0].TabVisible := False;
    PageControl1.Pages[1].TabVisible := False;
    etc...

Upvotes: 1

Related Questions