none
Show multiple forms on a form but there is a problem with the tabcontrol appearing topmost as the mdi parent RRS feed

  • Question

  • Hello,

    I am using a Winform application in VS2017. I have a tabcontrol Form on Form1.vb[Designer] which is programmatically controlled by a combobox in a docking panel beside the tabcontrol Form. The user will be able to change the current tabbed document in combobox's dropdown list. The Form1 is set as the Mdi parent form. On the left of the Docking panel is the Panel with two command buttons to load two other forms into Form1.The problem occurs when I clicked the two command buttons, the two other forms load, but they load in the background (and they are not seen by the viewer) while the tabcontrol form remains  topmost. How do I hide the tabcontrol form & the combobox in the docking panel so that when a user clicks the command buttons, the other two forms load topmost?

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim frm1 As New SubForm1
            frm1.MdiParent = Me
            frm1.Show()
        End Sub
    
        Private Sub BtnBooks_Click(sender As Object, e As EventArgs) Handles BtnBooks.Click
            Dim frm1 As New SubForm1
            frm1.MdiParent = Me
            frm1.Show()
        End Sub
    
        Private Sub BtnAuthor_Click(sender As Object, e As EventArgs) Handles BtnAuthor.Click
    
            Dim frm2 As New SubForm2
            frm2.MdiParent = Me
            frm2.Show()
        End Sub
    

    Thank you in advance for your help.

    Monday, April 22, 2019 3:14 AM

Answers

  • Hi,

    Are you trying to block the parent form's controls from the child form?

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("user32")>
        Public Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
    
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.IsMdiContainer = True
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim frm1 As New SubForm1
            frm1.MdiParent = Me
            frm1.Show()
            SetParent(CInt(frm1.Handle), CInt(Me.Handle))
        End Sub
    
    
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim frm2 As New SubForm2
            frm2.MdiParent = Me
            frm2.Show()
            SetParent(CInt(frm2.Handle), CInt(Me.Handle))
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by wirejp Monday, April 22, 2019 10:55 PM
    Monday, April 22, 2019 6:27 AM

All replies

  • Hi,

    Are you trying to block the parent form's controls from the child form?

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("user32")>
        Public Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
    
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.IsMdiContainer = True
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim frm1 As New SubForm1
            frm1.MdiParent = Me
            frm1.Show()
            SetParent(CInt(frm1.Handle), CInt(Me.Handle))
        End Sub
    
    
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim frm2 As New SubForm2
            frm2.MdiParent = Me
            frm2.Show()
            SetParent(CInt(frm2.Handle), CInt(Me.Handle))
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by wirejp Monday, April 22, 2019 10:55 PM
    Monday, April 22, 2019 6:27 AM
  • HI Alex,

    Thank you for your response. It is almost the solution which I am looking for. I do not want to block all of the parent form's controls from the child forms, only block the tabcontrol form. When I tried your solution it is also blocking the left-hand panel menu with the command buttons for the "Authors", "Tours" and "Events". I would this left-hand panel of command buttons to appear on the child forms. Below is a screenshot capture of what happens when I apply your solution

    I would like to achieve the effect as shown the attached video at time interval of 14mins:54sec:-

    VB.NET, C# UI Desıgn Advanced Modern Form

    Monday, April 22, 2019 12:16 PM
  • Hi Alex,

    I fixed my problem by updating your code to hide the tabcontrol on Form1 and the dock panel and combo box in each of your command button. I added another command button to display the tabcontrol, dock panel and combo box again:-

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("user32")>
        Public Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
    
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.IsMdiContainer = True
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            TabControl1.Hide()
            Dock1.Hide()
            Label.Hide()
            ComboBox1.Hide()
            Dim frm1 As New SubForm1
            frm1.MdiParent = Me
            frm1.Show()
            SetParent(CInt(frm1.Handle), CInt(Me.Handle))
        End Sub
    
    
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            TabControl1.Hide()
            Dock1.Hide()
            Label.Hide()
            ComboBox1.Hide()
    
            Dim frm2 As New SubForm2
            frm2.MdiParent = Me
            frm2.Show()
            SetParent(CInt(frm2.Handle), CInt(Me.Handle))
        End Sub
    
      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button2.Click
            TabControl1.Show()
            Dock1.Show()
            Label.Show()
            ComboBox1.Show()
    End Sub
    End Class
    
    
      

    I have one follow up question in regard to the design of the Form1. The layout is made up of a horizontal panel at the top and it meets a vertical panel on the left. The point where these two panels meet, one can see the black outline of the top of the panel containing the command buttons. I tried to change the backcolor to green but I can still see the black outline. How to remove the black outline of the panel?

    Thanks



    • Edited by wirejp Monday, April 22, 2019 9:01 PM
    Monday, April 22, 2019 7:44 PM