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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking away from a control to lose its focus?

Status
Not open for further replies.

gdrenfrew

Programmer
Aug 1, 2002
227
GB
Hello,

I've got a form, with a customer control on it. The custom control has panels, numeric updowns etc.

When the numeric updown has the focus, I then want to click away from the numericupdown so it loses the focus.

However, I don't know how to make the panel_click event take the focus to the panel, or even to the form.

Can anyone help how to do this please?

Thanks (am a bit rubbish at c# and am bugfixing someone else's app).
 
panel1_click(object sender, EventArgs e)
{
this.Focus();
this.Select();
}

That will select the form;
 
Thanks JurkMonkey

And if there were many panels on the form, would each need its own handler - or can I write a handler for "everything except the numericupdown"? Does the numericupdown know there's been a mouseclick that wasn't on it?

Will give the above a go though.
thanks
 
You can point each panel at the same event handler. The easiest way to do that is to hold down ctrl and click on each panel then go to the lightning bolt icon (in the properties) and double click on the "Click" event. Then put your this.Focus() and this.Select() code in that event handler and you're off like a prom dress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top