Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread ViewPort / ShowModal / ShowMessage
Sat, Feb 23 2019 12:23 PMPermanent Link

Eivind

All

Recently I have been working on some projects that has som very long forms. The form in question is 5.500 pixels high. Content within the form is displayed in my own collapsible panels (TBasicPanel). Depending on where the user are on the form I pop up other Modal forms using the code below:

  With frmEntitySetup do begin
     Top := Application.ViewPort.Height div 2 - Height div 2 + Application.ViewPort.ScrollTop;
     Left := Application.ViewPort.Width div 2 - Width div 2;
     ShowModal;
  end;

I cannot use layout of the form to Center as that will always show the form in the center of the ViewPort. Anyhow, some strange stuff happens:

1. The first time the modal form is shown, I create it and then call the above code. This results in the ViewPort scrolls all the way to the top and then show the form. However, the next time I show the form and its not created, the form show perfectly in the middle of the screen where the user works.

2. When the modal form is created and shown a second second time it is show perfectly as mentioned above. However, when closing this modal form the ViewPort scrolls to the top.

Then over to my next problem with ShowMessage dialog. Every time I call ShowMessage from any scroll points, it always scrolls the ViewPort to the top. No exception.

I must surely be doing something wrong here. PS. In the main forms Show proc I call:

  With Application do begin
     ViewPort.OverflowY:=otAuto;
     ViewPort.OverflowX:=otAuto;
     surface.Constraints.min.width:=(Self.width+40);
     surface.Constraints.min.height:=(Self.height+40);
  end;

to activate the scrollbars.

So yea, I'm a little bit stuck here. Not so good for my users having to scroll down 5.000 pixels every time they show a modal dialog or a ShowMessage Dialog.

So if my code to show the form could be changed so it does not scroll to the top, that would be great. How do I solve the ShowMessage issue?

Thanks for helping me piece this together!

Eivind
Sat, Feb 23 2019 12:58 PMPermanent Link

Eivind

Ok, a very interesting observation after testing more....

The code to show the modal form is called from a TImage.OnClick event. As mentioned it scrolls the view port to the top. However, if the same code is called from a TButton it is no problems!! The ViewPort does not scroll to the top in showing the modal form OR ShowMessage. Ok, I could possibly start using Icon buttons and add these images I use for buttons to the image library

Now, most of the ShowMessage and Message dialogs is executed from a menu items in Popup Menu. This will always scroll the ViewPort to the top. How can I solve for this?

If needed I'll create a small test project you can see this.
Sun, Feb 24 2019 1:14 AMPermanent Link

Eivind

Please test the below link for a demo on what I mean:

https://www.reachfx.no/Project1.html

This project and the main form is how many of my forms are configured for the long form. Obviously, when the form is shown in real time the panels are collapsed and the user can open any panel he want. So my problem is to have the ViewPort NOT scroll to the top after a modal dialog or a ShowMessage is shown when clicking on a TImage, TIconButton or a Menu Item.

As described in the project, if you click on the buttons first, the menu items works correctly. However, if you click on the TImage or TIconButtons first, the TMenu does not behave correctly.

I am thoroughly confused now Smile

Eivind
Sun, Feb 24 2019 7:51 PMPermanent Link

Raul

Team Elevate Team Elevate

On 2/24/2019 1:14 AM, Eivind wrote:
> Please test the below link for a demo on what I mean:
> https://www.reachfx.no/Project1.html
>
> This project and the main form is how many of my forms are configured for the long form. Obviously, when the form is shown in real time the panels are collapsed and the user can open any panel he want. So my problem is to have the ViewPort NOT scroll to the top after a modal dialog or a ShowMessage is shown when clicking on a TImage, TIconButton or a Menu Item.

I suspect the issue is related to focus.

AFAIK onclick EWB remembers last active control so when focus comes back
to the main form it will set it there to keep things consistent.

TButton is focusable and works fine - it gets refocused after the click.

TImage is not a focusable control so EWB i think tries to redirect focus
and ends up finding a control likely with  taborder  or such which
happens to be on top.

Anyways, i don't have a good solution to this but would start with
forcing focus to another focusable control on panel or maybe even
parenting timage with a control that can have a focus (like tpanel) and
then making sure it has focus when clicking on timage.

Raul
Mon, Feb 25 2019 10:29 AMPermanent Link

Eivind

@Raul

Yea, I was worried it was something like that. Could possibly understand it for the TImage but the TIconButton and TMenu is supposed to be used for clicking on. If I have no other choice I did experiment with having a TEdit control on each of those section and set the height to 0. Before every call to ShowMessage og ShowModal I will call Edit1.SetFocus. This seems to be working and prevented the VeiwPort to scroll to the top. However, if the TEdit was a bit outside of the view it would scroll to put that edit box inside the view. Anyhow, better than having to be scrolled to the top. Maybe I need multiple of those TEdit boxes inside each of those panels to make it work perfectly.

Not a perfect world, but at least much better than the user having to scroll down 5.000 pixels every time Smile

Eivind
Mon, Feb 25 2019 10:51 AMPermanent Link

Raul

Team Elevate Team Elevate

On 2/25/2019 10:29 AM, Eivind wrote:
> Yea, I was worried it was something like that. Could possibly understand it for the TImage but the TIconButton and TMenu is supposed to be used for clicking on.

Elvind,

TMenu issue i think is that unless you click on anything else the 1st
panel (on top) still has focus (the down button on top left is
highlighted in blue if you notice so that is where focus goes).

TIconbutton is not focusable.

TMenu is focusable but i wonder if it does not steal focus as you would
otherwise be losing focus in a normal form app when opening/closing menu
as well.

Hopefully Tim or others have better a suggestion for a cleaner solution.

Raul
Image