Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controls.Remove() and Focus

Status
Not open for further replies.

RedPenn

Programmer
Jun 29, 2003
1
GB
Hi,

When I remove a TextBox that has the keyboard focus from a Panel using Controls.Remove, the application seems to have a focus problem and its close button becomes disabled. If I use Add to recreate the Control, without having focus, the app then recovers. It seems like the apps message processing is hanging up somehow.
What can I do to Remove the Control without this problem ?

Thanks,
- Paul.
 
You could send a tab key to move the focus allong to the next control.

One question, when you are removing the control from tyhe control collection are you removing all of the controls event handlers?

Code:
//Remove the buttons click event, use the -= operation
this.button1.Click -= System.EventHandler(this.button1_Click)
//Remove the control any other events and then the control....
 
Error in code posted in last post I have now tested this and it works fine.

Code:
private void button1_Click(object sender, System.EventArgs e)
		{
			this.button1.Click -= new System.EventHandler(this.button1_Click);
			this.Controls.Remove(this.button1);
		}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top