Controls in container form come over child form?

后端 未结 8 2239
天涯浪人
天涯浪人 2020-12-01 20:40

In a container form I have menu and buttons to open ther forms. \"enter

Here I am fac

8条回答
  •  生来不讨喜
    2020-12-01 20:46

    It appears as though that form is a sibling of those other child controls. Do you have to open it as a child of that window? Can't it be like a non-modal dialog box and not a child window of that main form?

    If it has to be within that main form and a sibling of those controls, then you're going to have to set the Z-Order of it. There's no property for that, so you're going to have to look toward the Win32 API call, SetWindowPos:

    [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    public static extern bool SetWindowPos(
    int hWnd, // window handle
    int hWndInsertAfter, // placement-order handle
    int X, // horizontal position
    int Y, // vertical position
    int cx, // width
    int cy, // height
    uint uFlags); // window positioning flags
    
    
    const uint SWP_NOSIZE = 0x1;
    const uint SWP_NOMOVE = 0x2;
    const uint SWP_SHOWWINDOW = 0x40;
    const uint SWP_NOACTIVATE = 0x10;
    

    And call it something like this:

    SetWindowPos((int)form.Handle,   // that form
                 (int)insertAfter.Handle,  // some other control
                 0, 0, 0, 0,
                 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
    

提交回复
热议问题