' Collection of code snippets by Arne VajhÃ¸j 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace E
    Public Class MainForm
    Inherits Form
        Private button1 As Button
        Private textBox1 As TextBox
        Public Sub New()
            InitializeComponent
        End Sub
        Private Sub InitializeComponent()
            textBox1 = New TextBox
            button1 = New Button
            SuspendLayout
            textBox1.Multiline = True
            textBox1.Location = New Point(50, 50)
            textBox1.Size = New Size(200, 50)
            button1.Location = New Point(50, 150)
            button1.Size = New Size(200, 50)
            button1.Text = "Åben sub form"
            AddHandler button1.Click, AddressOf Button1Click
            ClientSize = New Size(300, 250)
            Controls.Add(button1)
            Controls.Add(textBox1)
            Text = "Main Form"
            ResumeLayout(False)
        End Sub
        Public ReadOnly Property TB() As String
            Get
                Return textBox1.Text
            End Get
        End Property
        Sub Button1Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim sf As SubForm = New SubForm(Me)
            sf.ShowDialog
        End Sub
    End Class 

    Public Class SubForm
    Inherits Form
        Private mf As MainForm
        Private textBox1 As TextBox
        Public Sub New(ByVal mf As MainForm)
            Me.mf = mf
            InitializeComponent
        End Sub
        Private Sub InitializeComponent()
            textBox1 = New TextBox
            SuspendLayout
            textBox1.Multiline = True
            textBox1.Location = New Point(50, 50)
            textBox1.Size = New Size(200, 50)
            textBox1.Text = mf.TB
            ClientSize = New Size(300, 150)
            Controls.Add(textBox1)
            Text = "Sub Form"
            ResumeLayout(False)
        End Sub
    End Class 

    Public Class TestClass
        <STAThread()> _
        Public Shared Sub Main(ByVal args As String())
            Application.Run(New MainForm)
        End Sub
    End Class 
End Namespace
