How do I make the subform stay on top

mjmartin

Registered User.
Local time
Today, 23:05
Joined
Jul 29, 2004
Messages
28
I've got a form which will have several subforms in it. I've got a button by each subform with a '+' sign on it. When the user clicks the '+' sign, the subform gains a red border and is enlarged over other controls, that '+' sign then becomes a '-' sign and when pressed returns everything back to normal again.

The problem is, when my VBA code resizes the subform, it's 'behind' the nearest subform so you can't see it all, how can I 'Send to front' the subform in VBA?

Here's a screenshot of my problem
 
What method did you use to resize it? Can I see the code?
 
The code's pretty simple...

Code:
Private Sub gymcentrezoom_Click()
If gymcentrezoom.Caption = "+" Then
'Perform the zooming operation
  'add_gymcentre.width = add_gymcentre.width
  add_gymcentre.Height = add_gymcentre.Height + 1220
  add_gymcentre.BorderColor = vbRed
  add_gymcentre.BorderWidth = 2
  add_gymcentre.BorderStyle = 1
  add_gymcentre.Form.RecordSelectors = True
  add_gymcentre.Form.NavigationButtons = True
Else
'Perform the restoring operation
  'add_gymcentre.width = add_gymcentre.width - 320
  add_gymcentre.Height = add_gymcentre.Height - 1220
  add_gymcentre.BorderColor = vbRed
  add_gymcentre.BorderWidth = 0
  add_gymcentre.BorderStyle = 0
  add_gymcentre.Form.RecordSelectors = False
  add_gymcentre.Form.NavigationButtons = False
  gymcentrezoom.Caption = "+"
End If
End Sub
 
I can't see a problem with your code and there is no reason to get complicated. Where is the gymcentrezoom.Caption = "-"? What I think is the problem is exactly what you said, it is to do with the z-index of the subform object. However I don't think more code is necessary not unless you intend to do something more complicated. Simply select the subform object that is going to zoom click on edit/cut, click on the detail of the form making sure no other control is selected then paste it and reposition it. Tell me if it works then.
 
yeah, must have chopped the '-' caption of that If clause, it goes in the part where if caption = '+' then change the caption to '-'

I read somewhere on the Microsoft site that you can only change the ZOrder (aka 'Send to Back' and 'Bring to Front') in Design time which really sucks.

I ended up writing some code which moves every other control lower than the subform that's being zoomed, down in the form.
 
mjmartin said:
I read somewhere on the Microsoft site that you can only change the ZOrder (aka 'Send to Back' and 'Bring to Front') in Design time which really sucks.
Not really true but it is complex api. Did cutting an pasting not work for you? I've tried just now and it worked. You would only need to change the z-index while the form is open if the subforms forms are mutually frog-leaping over each other on different events. The way I understood it you only needed to zoom the one subform over the other and therefore could be set up in design.
 
That was only an exmple screenshot, I've got about 4-5 sub-forms per form with this problem.

Have you got any example code for changing the zorders of subforms?
 
Mjmartin I have given this some thought. Subforms are not designed to be overlapped. Like I said there is going to be one of the subforms on top however its border is not going to be drawn where it overlaps and it is tough to change the index of the subform because it doesn't have a handle.

I would seriously reconsider your design.

If you still want to peruse the idea of a zooming window idea I have a possible solution. What you would do is get rid of all the sub forms and open forms in their place.

These forms are open when the main form loads and are made child to the main form (i.e are contained by the main form). You would have to make these forms frameless so they look like subforms or popups and aren't moved accidentally. You can make a border with a rectangle or lines. Then you set the starting position, which is measured relative to the top left corner of the parent window. You can use MoveSize on those forms onload events other wise use SetWindowPos. Then resize the child windows to minimise remebering to resize your border too.

On the maximise events you would resize the child windows.

I have shown the basics of the API in the Code Repository. The only thing I haven't covered is how to set the windows parent, which is fairly straightforward. Study these first:

Resize window

SetParent

SetWindowPos
 
Last edited:

Users who are viewing this thread

Back
Top Bottom