Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


The ScrollBar of the MDI From ???

Posted on 2002-07-15
Medium Priority
Last Modified: 2008-03-10
I have a MDI Form (main) and the other form are very large an the have many controls. When i open this form of course put visible the scrollbar both.

My question is:

How i can manipulate this scrollbar when the control focus get out of the view limits without the the operator move the scrollbar manually ?.
Question by:turquito
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
  • 5
  • 4
  • 2
  • +2

Expert Comment

ID: 7156932
You might want to set the WindowState property on the child to vbMaximize.  This will "merge" the forms together and allow the MDI form to act like a window for the child.  It will also allow your user to tab between fields that are on the child and move the viewable area along with the field.

Accepted Solution

schworak earned 600 total points
ID: 7158268
That won't work because once the inner form is maximized the scroll bars are removed from the MDI form.

If you really must control the scrollers of the MDI form I fear you may have to do some API calls.

There are a couple other solutions. You could put all your controls on a picture box within a form and keep the location of the current control within view by moving the picture box. I have done this on a couple projects.

Another way would also require a single API call to the SetParent function to take your existing form and make it a child of a picture box. You then move the picture box as described above and the form will follow and be inside the picture box. That isn't all that great though.

Expert Comment

ID: 7158451
well, shows you how much there is to know about programming.  Even in Basic.  I usually don't attempt to put all of the controls on the same form unless I have to and then I use a tab control to separate them if I have to.  Thx, schworak.  You learn something new every day.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 7172676
Well, may i didn´t more clear on my question, I will try to be specific.

I have a MAIN FORM ( MDIForm ), and the Form Child are more Width and Heigth that the Main Form, of course the Main Form put Visible the Scroll Bar ( H - V Scroll), I want manipulate this Scroll when the cursor move througth the From Child, something that the Web Page...

Expert Comment

ID: 7172790
Here is an experiment to try. This may be what you are looking for....

Create a project.

1) MDIForm1 (your MDI form)
2) Form1 (your editable form)
   a) Place several text box controls on the form
   b) Each named Text1 (this is a control array)
   c) Space them out around the form as you like
3) Add the following code to Form1
4) Run the program making sure both forms load
5) Make sure the MDI form is smaller than Form1
6) Tab from text box to text box.
(not perfect but with a little adjusting to your own needs this should be about what you are after)

Option Explicit

Private Const SM_CYCAPTION = 4
Private Const SM_CXFRAME = 32
Private Const SM_CXHSCROLL = 21
Private Const SM_CYHSCROLL = 3
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Sub Text1_GotFocus(Index As Integer)
    Dim t As Long   ' Top
    Dim l As Long   ' Left
    Dim b As Long   ' Bottom
    Dim r As Long   ' Right
    Dim VW As Long  ' Viewable Width
    Dim VH As Long  ' Viewable Height
    VW = MDIForm1.ScaleWidth - GetSystemMetrics(SM_CXHSCROLL) * Screen.TwipsPerPixelX
    VH = MDIForm1.ScaleHeight - GetSystemMetrics(SM_CYHSCROLL) * Screen.TwipsPerPixelX
    l = Text1(Index).Left + Me.Left + GetSystemMetrics(SM_CXFRAME) * Screen.TwipsPerPixelX
    t = Text1(Index).Top + Me.Top + GetSystemMetrics(SM_CYCAPTION) * Screen.TwipsPerPixelX
    r = l + Text1(Index).Width
    b = t + Text1(Index).Height
    If l < 0 Then Me.Left = Me.Left - l
    If t < 0 Then Me.Top = Me.Top - t
    If r > VW Then Me.Left = Me.Left + VW - r
    If b > VH Then Me.Top = Me.Top + VH - t
End Sub

Expert Comment

ID: 7172792
Please reject wensinkg's answer as it will not work.

Expert Comment

ID: 7172804
If it wasn't clear before I ADMIT MY MISTAKE!

Expert Comment

ID: 7173045

Sorry, the request to reject your answer wasn't an attack at you. The idea not working was an honist mistake. It even sounded good to me until I tried it.

I just wanted to get this question out of the LOCKED state that it is in at the moment.

Hope I didn't hurt any feelings, that wasn't my intension. Guess I should have explained a little more when I made the request myself.

Expert Comment

ID: 7173184
That's OK.  I shouldn't have reacted so badly.  There are a lot of reasons that I can't go into here but... well you know, I'm sure.  The worst is that I am a MCP in Visual Basic and it is clear by the response from the requestor I didn't really understand what was needed.  I learn from my experiences and I now don't just jump in with an answer without asking for clarification when needed.  Thanks for understanding.

Author Comment

ID: 7194845
mybe i was not clear on my question, i try explain again...

I have a MDIFrom how principal form, i need input many information and i divide this on several form (child), but i have some form(child) that are very large an activate the MDIform Scroll's, my question is :

If i have code on every textbox, when i pulse Enter the focus change on other textbox and sometimes this focus getout the view and i have pulse on the scroll...

I want that this form(child) can move how to do a Web Page, HOW I CAN DO THAT ????

Expert Comment

ID: 7194915
Turguito, let me restate what you are looking for just so I can be sure I understand what you are trying to do. Correct me if I have this wrong.

1. You have form A which is your MDI form
2. You have form B which is larger than form A
3. You want the text box on form B to be visible on the screen when the user enteres (gets focus) on it.

I don't understand where the reference to WEB PAGE comes fromin your last comment unless you mean you want it to scroll up/down like a web page does when you move from field to field.

If the above assumptions are correct, the example I gave you will do exactly what you are asking.

If you want a single scroller on the side of the window and your form to fill all of the MDI form, you are not going to be able to make that work ever. Sorry. You would need to use another method more like placing a picture box on a form with a scroller and then putting your controls within that picture box. You can then scroll the picture box up/down.

When an MDI form has a child form maximized, the scrollers are gone. Always. The form must be of normal size in order for it to use the scroller bars.

Does this help any?
LVL 49

Expert Comment

ID: 8012467
Hi turquito,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept schworak's comment(s) as an answer.

turquito, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 8095545
Comment from expert accepted as answer

E-E Admin

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

704 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