Solved

Working area in a MDI form

Posted on 2004-04-16
13
2,558 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 49

Author Comment

by:Ryan Chong
Comment Utility
Still waiting for any suggestion..
0
 
LVL 3

Expert Comment

by:Lektran
Comment Utility
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 49

Author Comment

by:Ryan Chong
Comment Utility
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
 
LVL 3

Expert Comment

by:Lektran
Comment Utility
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 49

Author Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
i dont quite understand, i can't find a form method called getWorkingArea
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 49

Author Comment

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

MDIForm.getWorkingArea()
0
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
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 49

Author Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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 49

Author Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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 49

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now