Form.Canvas corrupted when Form is mirrored for BiDiMode
Original Reporter info from Mantis: Avishai
-
Reporter name: Avishai
Original Reporter info from Mantis: Avishai
- Reporter name: Avishai
Description:
In Windows OS, when a Form is set to BiDiMode:= bdRightToLeft, the Form should be Mirrored so that the Close, Maximize and Minimize buttons are on the Left and the Icon and Caption are on the Right. (See http://msdn.microsoft.com/en-us/goglobal/bb688119.aspx) I can achieve this with the following code, but the Form's Canvas becomes unusable.
procedure MakeFormRightToLeft(AForm: TObject);
{ Make Form RightToLeft - Windows ONLY! }
begin
{$IfDef Windows}
if AForm is TForm then
with AForm as TForm do begin
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE)
or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
invalidate;
end;
{$EndIf}
end;
The Form's Canvas becomes Black. If you have Edit components on the Form, as soon as you leave the first Edit component, the canvas of the Edit component is mirrored and echoed to the Top-Right corner of the Form's canvas and is visible. Top-Right is now (0,0) and this is correct.
Also, I must leave the Form's BiDiMode:= bdLeftToRight to keep the Form Caption in it's correct location. If the Form BiDiMode:= bdRightToLeft, the Caption is misplaced near the Minimize Button.
I have found that I can do a Form.Repaint in the OnResize event and this will partially correct the problem, but only when you make the Form smaller. If you make it larger, it returns to Black. But if I Maximize the Form and then return it to Normal in the OnShow event, then it will remain Gray. But the Echoed Edit Canvas is still visible in the Top-Right corner.
My present workaround is simply to cover the Form canvas with a Panel Align:= alClient and it becomes the Parent of all controls. I set the Panel BiDiMode:= bdRightToLeft. It works, but it is a dirty solution.
Mantis conversion info:
- Mantis ID: 20506
- OS: Windows
- OS Build: 7
- Monitored by: » Avishai (Avishai)