Link to home
Start Free TrialLog in
Avatar of ITPOL
ITPOLFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I stop the childform overlapping the menubar and statusbar when i use Setparent?

As a test app, I have a .net MDI parent form, with a standard menubar and statusbar.  On the 'new' button click, I start a new process, get it's window handle using .MainWindowHandle, and pass it to SetParent, to make it a child of the main form.  This works, however if I maximize the child window it overlaps the menubar and the statusbar.  It also overlaps the menu/status bar when the form is moved around inside the client area.

Any ideas how i stop this?  I only want it to expand into the main client area.

Many Thanks in advance
Dim p As New Process
        p.StartInfo.FileName = "notepad.exe"

        p.Start()
        Threading.Thread.Sleep(1000)
        SetParent(p.MainWindowHandle(), Me.Handle)

Open in new window

Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

This is what I use in a MDI...
this code will fill inthe MDI area and check to make sure that it is not running already in the background under someother screen.
This code will also kept the Maximized Child Forms from flickering when opening


Public Const WM_SETREDRAW As Integer = &HB
Public Declare Auto Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean

'ADD this to your button or menu click
Dim objForm As Form = New frmMyNewScreen
                    With objForm
                        If Not CheckActive(.Name) Then
                            .Dock = DockStyle.Fill
                            SendMessage(Me.Handle, WM_SETREDRAW, 0, 0)
                            .Text = "My New Screen"
                            .MdiParent = Me
                            .Show()
                        Else
                            .Text = "My New Screen"
                            .MdiParent = Me
                            .TopMost = True
                        End If
                    End With
'' IF you use a StatusBar  then un-comment
 ''       StatusBar1.Height += 1
 ''   StatusBar1.Height -= 1     
    SendMessage(Me.Handle, WM_SETREDRAW, 1, 0)
    Me.Invalidate(True)

  Private Function CheckActive(ByVal pChildName As String) As Boolean
        '//////////////////////////////////////////////
        '//  Check to see if the form 
        '//  is already open for viewing
        '//////////////////////////////////////////////
        For Each childForm As Form In Me.MdiChildren
            If TypeName(childForm).ToUpper = pChildName.ToUpper Then
                childForm.Activate()
                Return True
            End If
        Next
        Return False
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ITPOL
ITPOL
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial