Forum > General
Make TForm RightToLeft
Avishai:
Hello,
I'm trying to make a Form that is a true RightToLeft Form. I have the following code that only works up to a point. It does mirror the Form, but for some reason the Form Client area is Black and I can't change it. Also the Form Caption ends up on the Left side when it should be on the Right. The only "solution" I have found so far is to put a TPanel on the Form and set it's Align property to alClient and make it the Parent of all other controls. That "fixes" the color problem, but it doesn't help with the Form Caption alignment. If anyone can help with these two points, I would be very much appreciative.
procedure TForm1.FormCreate(Sender: TObject);
{Make Form RightToLeft}
const
Frm_FIRST = $1000;
Frm_GETHEADER = Frm_FIRST + 31;
var
header: thandle;
begin
header:= SendMessage (Form1.Handle, Frm_GETHEADER, 0, 0);
SetWindowLong (header, GWL_EXSTYLE,
GetWindowLong (header, GWL_EXSTYLE) or
WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
SetWindowLong (Form1.Handle, GWL_EXSTYLE,
GetWindowLong (Form1.Handle, GWL_EXSTYLE) or
WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
Form1.invalidate;
end;
initialization
with Application do begin
NonBiDiKeyboard:= SysLocale.DefaultLCID;
BiDiKeyboard:= LangHeb;
SysLocale.MiddleEast := True;
BiDiMode := bdRightToLeft;
ActivateKeyboardLayout(LangDef, 0);
end;
Avishai:
I found a solution to the Form Caption Alignment. Setting the Form BiDMode to bdLeftToRight and the Panel BiDiMode to RightToLeft takes care of that problem. It's just a workaround and not a true solution, but it's working.
Avishai:
This seems to be better code, but it gives the same results.
procedure TForm1.FormCreate(Sender: TObject);
var
Params: TCreateParams;
begin
CreateParams(Params);
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle :=
WS_EX_LEFT or WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR or WS_EX_LAYOUT_RTL;
end;
Avishai:
OK, I'm down to this, but I still have the problem of the unchangeable BLACK Client Area of the Form. I've tried everything I can think of. I have a suspicion that it's the line Frm_GETHEADER = $101F; But I don't even have a clue of what to change it to;
procedure TForm1.MakeFormRightToLeft(Sender: TObject);
{Make Form RightToLeft}
const
Frm_GETHEADER = $101F;
var
Header: Thandle;
begin
with Sender as TForm do begin
Header:= SendMessage (Handle, Frm_GETHEADER, 0, 0);
SetWindowLong (Header, GWL_EXSTYLE,
GetWindowLong (Header, GWL_EXSTYLE) or
WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
SetWindowLong (Handle, GWL_EXSTYLE,
GetWindowLong (Handle, GWL_EXSTYLE) or
WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
invalidate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MakeFormRightToLeft(Sender);
end;
Zaher:
Hi,
first WS_EX_LAYOUTRTL not supported with all platforms, and it is also bad idea even in Windows, Microsoft made it in win98 to quick solve some problem with RTL but it is not used by its application like Office.
WS_EX_LAYOUTRTL have some bugs with some components like TreeView, ListView and PageControls
So we do not use WS_EX_LAYOUTRTL please.
Navigation
[0] Message Index
[#] Next page