Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working area in a MDI form

Posted on 2004-04-16
13
Medium Priority
?
2,568 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 54

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 54

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 54

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 54

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 54

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 54

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 1292 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 54

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 54

Author Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

886 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