Floating Window will not show after Main Document Window is minimised

I have a floating window that the user can open under the main window - it’s a help panel that the user can leave open and move out of the way - pretty much standard stuff. The main window is of the frame type document.

It works all fine if the user minimises the main window, AND the floating window is open, then both windows will minimise. On maximising the app, both windows are displayed as they should be.

However, IF the floating (help) window is then closed, and the main app window is minimised, then maximised again, the floating (help) window will never open again (when the button is pressed to activate it) until the app is restarted.

The floating window is activated by a canvas button:

WindowGraphHelp.Show

On minimising the Main Window, I have in the App, Event Handler, Deactivate:

WindowGraphHelp.Hide

Apart from that, I’m not sure what other code is relevant.

What code do you use to initially show the help window?

Thanks Greg.

The code is in the MouseDown event of a canvas button:

WindowGraphHelp.Show

The same window is closed with a different button within the window:

WindowGraphHelp.Close

If instead you used

dim wgh as new WindowGraphHelp Wgh.show

I bet it would do what you want.

Oh, and uncheck “implicit instance” on that window.

Well, that is getting somewhere.

The only issue I have now is I get an error in the Deactivate Event of the App.

App.Deactivate
Static reference to instance method: call this on an instance of class Window.
WindowGraphHelp.Hide

Means that there is no longer a window that can be referred to directly as

Add a property to your app called

theWindowGraphHelp   as  WindowGraphHelp

Initialise it somewhere like:

if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp

refer to it through your app with

theWindowGraphHelp instead of WindowGraphHelp

including in the deactivate event:

if theWindowGraphHelp <> nil then WindowGraphHelp.Hide

Thanks Jeff. What do you mean by “Initialise it somewhere” ?

If you know you will ALWAYS want such a window, do this once only in the App.open event

theWindowGraphHelp = new WindowGraphHelp

If you don’t know for certain, then whenever you were going to use such a window, put the initialisation code just before you use it, wherever you use it.

eg where you had

WindowGraphHelp.someproperty = "ABC"

code defensively by making sure you do have a window

if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp theWindowGraphHelp.someproperty = "ABC"

Getting clever, you could make theWindowGraphHelp into a computed property where the GET initialises the variable if it doesnt exist, transparently. That’s probably for another day.

You’re not wrong there. :slight_smile:

I still can’t get this working. As suggested I’ve added the property to the App:

theWindowGraphHelp As WindowGraphHelp

Fine so far.

I’ve included in the App.Open event:

theWindowGraphHelp = New WindowGraphHelp

Which I guess as expected shows an instance of the WindowGraphHelp at application start up - which is not really what I want.

So when you say: [quote]If you know you will ALWAYS want such a window, do this once only in the App.open event[/quote] do you mean if I ALWAYS want the said window shown at all times? I don’t. It should only happen when I press a button to show it.

I’ve been experimenting for the last 20mins or so and I seem to be going around in circles.

Also where you say:

theWindowGraphHelp.someproperty = "ABC"

Does this mean something like theWindowGraphHelp.Visible = True/False which I don’t have in my code. I thought I only had to deal with .Show or .Hide

I’ll try to clarify exactly where I’m at.

Creating the property, all fine.
The code in the Open event of the App. all fine.

Except that the window opens when the app starts. Ok, so I close it. Then how do I open it again?

If I use code in the button to open the window again I get errors:

theWindowGraphHelp.Show (This item doesn’t exist)
WindowGraphHelp.Visible = True (This item doesn’t exist)
WindowGraphHelp.Show (Static reference to blah bla bla…)

So, now I can’t work out how to show the window again regardless of any other requirements minimising the window and the deactivate method.

OK.
You dont always want the window to be shown.
Dont do theWindowGraphHelp = new WindowGraphHelp in app.open.

Later , you do this:

theWindowGraphHelp.Show

Do this instead:

if theWindowGraphHelp = nil then theWindowGraphHelp = new WindowGraphHelp theWindowGraphHelp.Show

What the heck have I done!

No, this doesn’t work either. I’d like to sort this out before one of us dies from frustration (ie. fawlty towers) :slight_smile:

I think there is something I have missed that you have assumed - maybe.

I get "this item doesn’t exist “theWindowGraphHelp”.

Another proposal:
The problem with a window as an app property is that if you try to close it and none existed yet, it will be created and shown once you address it in the manner above.
Instead you could do this:

In your WindowGraphHelp open method:

For q As Integer = 0 To WindowCount-1 Dim w As Window = Window(q) If w IsA WindowGraphHelp Then w.Show Return End If Next Dim w As New WindowGraphHelp

And in your close method:

For q As Integer = 0 To WindowCount-1 Dim w As Window = Window(q) If w IsA WindowGraphHelp Then w.Close Return End If Next

(Edited to use your naming scheme)

Thanks Ulrich, I’ll try that method.

One thing I have noticed is that with the code in the open event, as Jeff suggested, the window that does open on application start is NOT a floating window, ie. selecting the main underlying window then comes to the front.

I’ve checked by testing my previous working version and it does behave “normally” except for when the floating window is closed, the app minimised, then maximsied and the floating window cannot be opened again.

Maybe there is an issue with 2016R3 and Win7. I would have thought though, that others would have come across this before because what I want to do seems very straightforward.

I’ll test and report back shortly.

Unfortunately that code straight up gives an error:

Can’t find a type with this name
If w IsA FloatWindow Then

Maybe something to do with 2016R3 Win7 ???

No, sorry. I did not use your naming scheme first. Copy the edited code (or replace floatWindow by WindowGraphHelp)

Sorry Ulrich, that was my fault. Thanks for editing the code.

Well, I don’t get any errors anymore . . . and it works well . . . but it behaves similar like my original code (but not the same).

I’ve spent the last 15mins trying to trace and track down when and how the issue comes about. A “built version” does similar but not exactly the same as what occurs in the IDE debug mode.

The only other thing I can think of is in the App.Deactivate event where I still have the code:

WindowGraphHelp.Hide

Maybe the code needs chaning there?

I think so. I would replicate the close method, but this time with hide instead of close.

I get "this item doesn’t exist “theWindowGraphHelp”.

OK.
My fault… I said make theWindowGraphHelp a property of the app.

That might have been better in a global module, as a global variable.

If it is currently a property of the app, then you need to prefix with app.

Like this:

if app.theWindowGraphHelp = nil then app.theWindowGraphHelp = new WindowGraphHelp app.theWindowGraphHelp.Show