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);
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);