AcceptButton for a UserControl?
-
I'm building a usercontrol that has multiple buttons on it, and i need to set one of them as the accept button, but i can't find anything about how to do this. From what i can see it is only accessable from the Forms.Form not Forms.UserControl... Is this entirely the truth, or can I still somehow set this to work so it validates against my "Ok" button, when someone hits enter. string Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful + " people."; Why is common sense such an un-common comodity?
-
I'm building a usercontrol that has multiple buttons on it, and i need to set one of them as the accept button, but i can't find anything about how to do this. From what i can see it is only accessable from the Forms.Form not Forms.UserControl... Is this entirely the truth, or can I still somehow set this to work so it validates against my "Ok" button, when someone hits enter. string Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful + " people."; Why is common sense such an un-common comodity?
Your user control can't have an
AcceptButton
property because what happens if there are multiple user controls on the same form and all have that property set? which is the one that counts? A workaround is to expose a public read only property named something likeDefaultButton
, and have it return a reference to your OKButton
. Then, the form can set itsAcceptButton
property to that reference. Or the other way around, make the form pass a reference to itself to the user control, so it can set the form'sAcceptButton
property (I like the first way better). -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005