1 Replies - 324 Views - Last Post: 29 April 2019 - 01:23 PM Rate Topic: -----

#1 wire_jp   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 10-January 19

tabcontrol as mdiparent prevents multiple forms loading topmost

Posted 21 April 2019 - 08:33 PM

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


Is This A Good Question/Topic? 0
  • +

Replies To: tabcontrol as mdiparent prevents multiple forms loading topmost

#2 wire_jp   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 52
  • Joined: 10-January 19

Re: tabcontrol as mdiparent prevents multiple forms loading topmost

Posted 29 April 2019 - 01:23 PM

I got my issue fixed:-

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



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1