Solved

Working area in a MDI form

Posted on 2004-04-16
13
2,560 Views
Last Modified: 2012-06-27
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..)?
0
Comment
Question by:Ryan Chong
  • 8
  • 5
13 Comments
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10848725
Still waiting for any suggestion..
0
 
LVL 3

Expert Comment

by:Lektran
ID: 10848734
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
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10848779
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 3

Expert Comment

by:Lektran
ID: 10848801
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
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10848979
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
 
LVL 3

Expert Comment

by:Lektran
ID: 10849022
i dont quite understand, i can't find a form method called getWorkingArea
0
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10849035
The Me object is referred to a MDI Form, so it can be as:

MDIForm.getWorkingArea()
0
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10849063
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
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10852451
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
 
LVL 3

Accepted Solution

by:
Lektran earned 323 total points
ID: 10852595
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
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10853438
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
 
LVL 3

Expert Comment

by:Lektran
ID: 10855468
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
 
LVL 50

Author Comment

by:Ryan Chong
ID: 10896879
Thanks for the explaination, Lektran, thks ;-) cheers
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question