TMyForm = class(TForm)
...
protected
procedure CreateParams(var aParams: TCreateParams); override;
end;
procedure TMyForm.CreateParams(var aParams: TCreateParams);
begin
inherited CreateParams(aParams);
//This makes the form stay ontop of the owner - Normally Modeless dialogs fall behind their owner
if Self.Owner <> nil then
aParams.WndParent := TForm(Self.Owner).Handle;
end;
//Note replace TForm(Self.Owner).Handle with the another Form Handle to make it stay on top of that form
How to make Focus Lines appear
Under XP, Vista and Win 7 the focus lines\box wont appear on Radio buttons and checkboxes
until you start tabbing or use the alt key. Typically if you open the dialog using keyboard
the focus will appear. But opening using the mouse it will disappear.
procedure TMainForm.FormShow(Sender: TObject);
begin
SendMessage(Self.Handle, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
end;
Stop controls disappearing in Win7 & Vista
There is a known problem with Delphi apps the first time you press Alt key or sometimes Tab key, all the checkboxes, buttons, radio buttons all disappear.
The easiest fix I've found is this:
- Set Form.KeyPreview := true; //all key events echoed to main form key events
- Watch for ALT and TAB keys. If found Invalidate all button controls.
// Win7 Update fix
procedure TVMainForm.TntFormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var bf: TBrowserFrame; i: Integer;
begin
UToolbox.Win7UpdateFix(Self, key);
for i := 0 to SmartTabs.Count-1 do
begin
bf := GetBrowserFrame(i);
bf.FixWin7Update;
end;
end;
procedure TVMainForm.CMDialogKey(var Msg: TCMDialogKey); //message CM_DIALOGKEY;
begin
inherited;
if msg.Charcode = VK_TAB then
Win7UpdateFix(Self, VK_TAB);
end;
...
procedure Win7UpdateFix(Form: TForm; CharCode: Word);
var i: Integer;
begin
if Assigned(Form) and (Win32MajorVersion >= 6) and (Win32Platform = VER_PLATFORM_WIN32_NT) then //Vista, Win7
begin
case CharCode of
VK_MENU, VK_TAB: //Alt or Tab
begin
for i := 0 to Form.ComponentCount-1 do
begin
if Form.Components[i] is TWinControl then
begin
//COntrols that disappear - Buttons, Radio buttons, Checkboxes
if (Form.Components[i] is TButton) or (Form.Components[i] is TTntButton)
or (Form.Components[i] is TRadioButton) or (Form.Components[i] is TTntRadioButton)
or (Form.Components[i] is TCheckBox) or (Form.Components[i] is TTntCheckBox) then
TWinControl(Form.Components[i]).Invalidate;
end;
end;
end;
end;
end;
end;
Transparent Form Areas
TMainForm = class(TForm)
...
protected
procedure CreateWindowHandle(const Params: TCreateParams); override;
...
end;
procedure TMainForm.CreateWindowHandle(const Params: TCreateParams);
begin
inherited;
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, RGB(60, 60, 60), 0, LWA_COLORKEY);
end;
procedure TMainForm.FormPaint(Sender: TObject);
var rClientRect:TRect;
begin
rClientRect := ClientRect;
Canvas.Brush.Color := RGB(60, 60, 60);
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(rClientRect);
end;
Aero Glass