Solved

Working area in a MDI form

Posted on 2004-04-16
13
2,563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 52

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 52

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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 52

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 52

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 52

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 52

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 52

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 52

Author Comment

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

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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