// 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) using System; using System.Drawing; using System.Windows.Forms; namespace E { public class MainForm : Form { private Button button1; private TextBox textBox1; public MainForm() { InitializeComponent(); } private void 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"; button1.Click += new EventHandler(Button1Click); ClientSize = new Size(300, 250); Controls.Add(button1); Controls.Add(textBox1); Text = "Main Form"; ResumeLayout(false); } public string TB { get { return textBox1.Text; } } void Button1Click(object sender, System.EventArgs e) { SubForm sf = new SubForm(this); sf.ShowDialog(); } } public class SubForm : Form { private MainForm mf; private TextBox textBox1; public SubForm(MainForm mf) { this.mf = mf; InitializeComponent(); } private void 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); } } public class TestClass { [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } } }