Forms: modal and stay-on-top



This relates to my earlier post about HTML Help, but it is a generic
question.

I have a mainForm, a helpForm and a modalForm.
The helpForm will show instructions. It should remain visible and accessible
at all times. HelpForm.formstyle:=fsStayOnTop.When the modalForm is opened
(say via a button click) from the mainForm, the helpForm may be in front of
or behind the modalForm, but it should definitely stay in front of the
mainForm. And even though the modalForm has focus, the helpForm must get
focus when the user clicks in it.

This I can not achieve in the normal way. The helpForm loses focus as soon
as the modalForm is opened and the user can not activate it.

So, I try this:

procedure mainForm.buttonClick(Sender: TObject);
// close helpForm when it's open, show modalForm
begin
helpForm.Close;
modalForm.ShowModal;
end;

procedure modalForm.FormShow(Sender: TObject);
// reopen helpForm
begin
HelpForm.Show;
end;

The helpForm closes and re-opens when modalForm is called by the button
click. It stays on top of the mainForm, behind modalForm. (Nb: I like this,
but do not understand why it doesn't show in front of modalForm; Help says
about fsStayOnTop: "This form remains on top of the desktop and of other
forms in the project, except any others that also have FormStyle set to
fsStayOnTop".)

This solution requires two separate actions: helpForm.close before the
button is clicked and helpForm.show in the modalForm.FormShow. If I move the
helpForm.close statement to the modalForm.FormShow as well, then the
helpForm becomes inaccessible if it was already open when the modalForm is
shown:

procedure modalForm.FormShow(Sender: TObject);
// close and reopen helpForm: this will not work - helpForm can not be
activated if it was already visible
begin
HelpForm.Close;
HelpForm.Show;
end;

If you've been able to follow me this far: is there an easier way of keeping
the helpForm visible and accessible while opening modal forms in the
application?
Tom





.


Quantcast