locked
how do i create sub forms in my main form RRS feed

  • Question

  • i checked the main form

    IsMdiContainer=true

    and the same the sub form i also checked

    IsMdiContainer=true

    and didnt find the way to display the sub fom in between the main form

    Please respond ASAP

    Thanks In Advence

    Sunday, September 6, 2020 7:36 PM

Answers

  • Hi

    Here is a stand alone example. Form1 needs SplitContainer1 (Horix split) with Panel1 containing 4 Buttons. Each of Form2, Form3 and Form4 are default, (I set BC just for differentiation)

    Try it out and see if it helps.

    Designer

    Running

    Form1 code

    ' Form1, Form2, Form3 and Form4
    ' SplitContainer (horix split) with
    ' Panel1 containing 4 buttons
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Dim Open As Form = Nothing
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		Text = "THIS IS FORM1"
    		With SplitContainer1
    			.Dock = DockStyle.Fill
    			.SplitterDistance = 40
    			.FixedPanel = FixedPanel.Panel1
    			.Panel1.BackColor = Color.PaleGoldenrod
    		End With
    	End Sub
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf2 As New Form2
    		With nf2
    			.Text = "THIS IS FORM2"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			.BringToFront()
    			Open = nf2
    		End With
    	End Sub
    	Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf3 As New Form3
    		With nf3
    			.Text = "THIS IS FORM3"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			Open = nf3
    		End With
    	End Sub
    	Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf4 As New Form4
    		With nf4
    			.Text = "THIS IS FORM4"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			Open = nf4
    		End With
    	End Sub
    	Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    		If Not Open Is Nothing Then Open.Close()
    	End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by MosheS Singer Monday, September 7, 2020 4:03 PM
    Sunday, September 6, 2020 7:52 PM

All replies

  • Hi

    Here is a stand alone example. Form1 needs SplitContainer1 (Horix split) with Panel1 containing 4 Buttons. Each of Form2, Form3 and Form4 are default, (I set BC just for differentiation)

    Try it out and see if it helps.

    Designer

    Running

    Form1 code

    ' Form1, Form2, Form3 and Form4
    ' SplitContainer (horix split) with
    ' Panel1 containing 4 buttons
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Dim Open As Form = Nothing
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		Text = "THIS IS FORM1"
    		With SplitContainer1
    			.Dock = DockStyle.Fill
    			.SplitterDistance = 40
    			.FixedPanel = FixedPanel.Panel1
    			.Panel1.BackColor = Color.PaleGoldenrod
    		End With
    	End Sub
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf2 As New Form2
    		With nf2
    			.Text = "THIS IS FORM2"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			.BringToFront()
    			Open = nf2
    		End With
    	End Sub
    	Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf3 As New Form3
    		With nf3
    			.Text = "THIS IS FORM3"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			Open = nf3
    		End With
    	End Sub
    	Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    		If Not Open Is Nothing Then Open.Close()
    		Dim nf4 As New Form4
    		With nf4
    			.Text = "THIS IS FORM4"
    			.ControlBox = False
    			.Location = New Point(0, 0)
    			.Dock = DockStyle.Fill
    			.TopLevel = False
    			.Parent = SplitContainer1.Panel2
    			.Show()
    			Open = nf4
    		End With
    	End Sub
    	Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    		If Not Open Is Nothing Then Open.Close()
    	End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by MosheS Singer Monday, September 7, 2020 4:03 PM
    Sunday, September 6, 2020 7:52 PM
  • thanks

    Please explain 

    Open = nf2

    Open = nf3

    Open = nf4

    please puvide the code for this calling sub or function

    and how it is opening the SubForm in this spot



    Sunday, September 6, 2020 8:08 PM
  • Hi

    All the code is there!

    Did you try it as a stand alone project?


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, September 6, 2020 8:10 PM
    Sunday, September 6, 2020 8:09 PM
  • OK now i see it thanks
    Sunday, September 6, 2020 8:16 PM
  • Thanks A milion

    it is working wonderfull

    Sunday, September 6, 2020 9:12 PM