I tried to mimic the changes you described below. This example works
for me in both the 1.0 and 1.1 .NET framework. However, to use buttons
inside a MDI parent form would be (IMO) way outside of convention.
Typically the parent's UI is all menu and toolbar driven. You will
notice that the button I have on the MDI parent form just sort of floats
above all the children. Also, if you haven't already, you should make
sure that your Button's EventHandler is being fired by adding a quick
messagebox:
MessageBox.Show("Yessir, I am indeed working");
FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();
That will at least tell you if your problem is in the spawning of child
forms or in the handling of the Button's Click delegate.
My slightly altered example is included below.
/kel
-----------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MdiExample {
public class Parent : Form {
private Button button = null;
public Parent() : base() {
button = new Button();
button.Text = "Bam!";
button.Click += new EventHandler(this.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
this.Controls.Add(button);
}
public void OnUIEvent(object sender, EventArgs e) {
if (sender.Equals(button)) {
Form f = new Child(this,Guid.NewGuid().ToString());
f.Show();
}
}
}
public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}
public static void Main(string[] args) {
Application.Run(new Parent());
}
}
}
Saso said:
Hi!
I tried the example you gave me... I have a Form (MainForm) on which I have
a button...
I edited the MainForm:
this.IsMdiContainer = true;
I edited FormTwo:
public FormTwo(Form parent, string text) : base()
{
this.MdiParent = parent;
}
When I press the button I execute:
FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();
Nothing happens
![Frown :( :(](/styles/default/custom/smilies/frown.gif)
What am I doing wrong?