CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    130

    Grey area around child form

    Hi all

    I have a MIDIForm with two child forms. (Form1 and Form2)

    Both the child forms are the same size and have identical properties set.

    When Form1 loads its fills the midiForm perfectly.

    When I hide form1 and show Form2, the form2 is "offset" down and to the right leaving a grey area on two sides (Top and left)

    Any idea what I am doing wrong?

    Many thanks

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Grey area around child form

    At a guess, I would say that you must make sure that your Form2's Left and Top properties are exactly the same as Form1's in run time, for example, put this into the Click event of the button you use to Hide Form1, and Show Form2 :
    Code:
    Private Sub Command1_Click()
     Me.Hide 'Hide Form1
     Form2.Show 'Show Form2
     Form2.Left = Form1.Left 'Set Form2's Left = To Form1.Left
     Form2.Top = Form1.Top 'Set Form2's Top = To Form1.Top
    End Sub

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Grey area around child form

    Yes. That would work.
    In fact you did nothing wrong, but there is an automatism which places the windows one under the other. A third window would again be positioned with another offset to the second window so that in case they all were visible you could see the title bars of all stacked windows.
    If you want the window to appear always in the same place as the first, Hannes' solution is perfect. Also you might wish to supply absolute coordinates like Form2.Move 0, 0 which always puts the window in the top left corner.

  4. #4
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: Grey area around child form

    One thing to add -- if the "grey area" is where the hidden form was, you might have to force the mdi parent to redraw itself. Either toss a DoEvents into your Form2 loading code or explicitly call "MDIForm.Refresh".

  5. #5
    Join Date
    Feb 2004
    Posts
    130

    Re: Grey area around child form

    Excellent. Many thanks for your help everyone.

    Have not tried it yet but it sounds like I have a few options now.

    Very grateful to you

    Regards
    Adrian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured