Working area in a MDI form

Hi,

I trying to develop an application, where a MDI got some other controls that are dockable. I got 4 dockable controls, the original dock position of the controls are Left, Top, Right, and Bottom.

As i open a Child Form, i got a function called "Fit Window", which will resize the child form to fix the remaining area in the center of the MDI form. Quite easy..

But the problem occurs when the dockable controls are dock to other area in the MDI form, Like a Right dock control is moved to Top dock area. This make now the Right Area "empty", and Top Area got 2 dockable controls. Then i click on the "Fit Window" function, the calculation of changing the Child Form's width and Height now become incorrect.

So, my question is:

Can we know the remaining Working Area of a MDI form easily?

or How do i know the position of a dockable control (Left, Top, Right, Bottom, even center..)?
LVL 56
Ryan ChongAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
LektranConnect With a Mentor Commented:
ok i've solved the dilemma completely(i hope)
the problem was that when mdiClient returned its size it was the size less the scrollbars

so heres my solution:
Public Sub FitWindow(ByVal frm As Form)
      Dim ctrl As Control
      For Each ctrl In Me.Controls
            If TypeOf ctrl Is MdiClient Then
                  frm.Size = ctrl.ClientRectangle.Size
                  frm.Left = 0
                  frm.Top = 0
                  Application.DoEvents()
                  frm.Size = ctrl.ClientRectangle.Size
            End If
      Next
End Sub

this makes the form small enough to get rid of the scrollbars
then DoEvents allows the system to get rid of the scrollbars
so we can refit the window to the actual MdiClient Size
0
 
Ryan ChongAuthor Commented:
Still waiting for any suggestion..
0
 
LektranCommented:
Try this:      

Public Sub SetFormSize(ByVal frm As Form)
      Dim ctrl As Control
      For Each ctrl In Me.Controls
            If TypeOf ctrl Is MdiClient Then
                  frm.Size = ctrl.ClientSize
                  frm.Left = 0
                  frm.Top = 0
            End If
      Next
End Sub
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Ryan ChongAuthor Commented:
Hi  Lektran,

Thks for the suggestion, but it's weird, the first time the "Fit Window" menu is clicked, the child form is resized, there still got some small area is Not covererd either at the right or bottom of the Working Area. And after i click the "Fit Window" menu again, the full Working Area now is covered fully..

hmm.. i'm trying to resolve it first.. will get back to you soon..

the code i use is:

Private Sub mnuFitWindow_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFitWindow.Activate
        Dim frm As Form = Me.ActiveMdiChild
        SetFormSize(frm)
    End Sub
0
 
LektranCommented:
try replacing this:
frm.Size = ctrl.ClientSize

with this
frm.size = ctrl.ClientRectangle.Size

I think they both refer to the same thing but it's worth a try
0
 
Ryan ChongAuthor Commented:
Hi Lektran,

I tried this:

frm.Size = Me.getWorkingArea

it works great actually.

Since i resolved the problem myself, can i PAQ this question with 0 pts? I will post a "Points to" to you, that thanks for your keen to assist.

thks
0
 
LektranCommented:
i dont quite understand, i can't find a form method called getWorkingArea
0
 
Ryan ChongAuthor Commented:
The Me object is referred to a MDI Form, so it can be as:

MDIForm.getWorkingArea()
0
 
Ryan ChongAuthor Commented:
Hi Lektran,

Disregard my comments above! I didnt realize that i get a function written as getWorkingArea with returned a Size object.

What a Joke!

I tried to figure out the problem, will get back to you this couple of days. Sorry about that..
0
 
Ryan ChongAuthor Commented:
Hi Lektran,

I was able to resolve the problem, by using this:

...
'Make sure all items are arrange to prevent scrollbars
        mnuMinimizeAll_Activate(Nothing, Nothing)
        mnuArrangeIcon_Activate(Nothing, Nothing)
        Application.DoEvents()
        frm.WindowState = FormWindowState.Normal
        mnuTileHorizon_Activate(Nothing, Nothing)

        frm.Height = leftSandBarDock.Height + IIf(SBar.Visible, 0, SBar.Height - 20) - 4
...

Where:
mnuMinimizeAll_Activate >> Minimize all child forms
mnuArrangeIcon_Activate >> Arrange Layout of child forms to Icons
frm.WindowState .. >> Set window state to Normal
mnuTileHorizon_Activate >> Horizontally align the forms.
Lastly:
Set the form's height by set it as the heght of Left side Dockable control (leftSandBarDock). And minus the height if Status bar (SBar) is shown.

A bit of workaround kind solution but it works.

For your solution of:

frm.size = ctrl.ClientRectangle.Size

It keep now showing the scrollbars, like a "bit" where it shows in first time, but not second time, then continue like that.. I certainly don't know why... you got this problem before?
0
 
Ryan ChongAuthor Commented:
Hi Lektran,

It's weird, why need to set the frm.Size twice in the Sub there ? If i remark the first frm.Size line the sub is Not working properly (still cant get rid of scrollbars problem)

Do you know why? If you also not very sure, it's ok.

Will PAQ this question soon, oh.. and of course you can answer the above question. thks ;-)
0
 
LektranCommented:
The reason you have to call the sub twice is because the mdiclient area is the available area on the mdiclient,
so if scrollbars are currently display on the mdiClient the available area is reduced by the size of the scrollbars.
So therefore when you get clientRectangle.size the first time the form resizes to whats available at the time,
after this is done the scrollbars are no longer need so they disappear thus leaving us with a gap around the edges
of the form.  So to fix this we give the application time to remove the scrollbars(DoEvents) and then get the new size of the mdiclient and resize the form accordingly

This is the best solution you could have received for the question posted
If you need me to explain further thats no problem
0
 
Ryan ChongAuthor Commented:
Thanks for the explaination, Lektran, thks ;-) cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.