user control host form gets disabled

G

Guest

My main form contains a panel which I use to host user controls
After I have added and then removed all instances of my user controls from the panel, then move focus away from and back to my app, my main form appears disabled

Is there something I need to be doing in my user control? If I use a standard control e.g. Button I don't get the problem
A simplified version of my code is shown below

using System
using System.Windows.Forms

namespace WindowsApplication

public class MyControl: UserContro

public MyControl(

this.Controls.Add(new Button())



public class Form1 : For

private Panel PanelMain
private MyControl t1

public Form1(

MenuItem menuAdd = new MenuItem("&Add",new System.EventHandler(this.Add_Click))
MenuItem menuRemove = new MenuItem("&Remove",new System.EventHandler(this.Remove_Click))
this.Menu = new MainMenu(new MenuItem[]{menuAdd,menuRemove})

PanelMain = new Panel()
t1 = new MyControl()

this.Controls.Add(PanelMain)


[STAThread
static void Main()

Application.Run(new Form1())


private void Add_Click(object sender, System.EventArgs e

this.PanelMain.Controls.Add(t1)
t1.Focus()


private void Remove_Click(object sender, System.EventArgs e

this.PanelMain.Controls.Remove(t1);
 
R

richlm

Turns out to be a known bug. There's a hot fix available from Microsoft
product support - see
http://support.microsoft.com/default.aspx?scid=kb;en-us;827534

richlm said:
My main form contains a panel which I use to host user controls.
After I have added and then removed all instances of my user controls from
the panel, then move focus away from and back to my app, my main form
appears disabled.
Is there something I need to be doing in my user control? If I use a
standard control e.g. Button I don't get the problem.
A simplified version of my code is shown below:


using System;
using System.Windows.Forms;

namespace WindowsApplication9
{
public class MyControl: UserControl
{
public MyControl()
{
this.Controls.Add(new Button());
}
}

public class Form1 : Form
{
private Panel PanelMain;
private MyControl t1;

public Form1()
{
MenuItem menuAdd = new MenuItem("&Add",new System.EventHandler(this.Add_Click));
MenuItem menuRemove = new MenuItem("&Remove",new System.EventHandler(this.Remove_Click));
this.Menu = new MainMenu(new MenuItem[]{menuAdd,menuRemove});

PanelMain = new Panel();
t1 = new MyControl();

this.Controls.Add(PanelMain);
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Add_Click(object sender, System.EventArgs e)
{
this.PanelMain.Controls.Add(t1);
t1.Focus();
}

private void Remove_Click(object sender, System.EventArgs e)
{
this.PanelMain.Controls.Remove(t1);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top