i have a problem with focus. not my own focus, but giving focus to a composite control within a groupbox.
if anyone is up for a challenge, try this and see what you can do to remedy my problem (shouldn't take more than a few minutes)
1. create a new project with a single form.
2. in that project, create a new UserControl named myUserControl.
3. myUserControl will be simple, just a label and a textbox; nothing more.
4. In your project's form, drop in a groupbox and a button; the button will reside in the form (not in the groupbox), and groupBox1 will contain myUserControl1.
5. set groupBox1's Enabled property to false.
6. hook up the Click event for the button and give it the following code:
void button1_Click_ClickedButton(object sender, EventArgs e)
{
groupBox2.Enabled = true;
this.ActiveControl = UserControl2 ;
}
7. Run the project, and ponder why the textbox in UserControl2 does not take focus when the button is clicked.
-
-
you could (I have no access to my computer right now) override the GotFocus event of the user control and set the focus to the textbox in there. Now each time the usercontrol gets the focus it will focus on the textbox...
-
vbrunner__ wrote:Answer: hook up the Enter event for the UserControl and give it the following code:
private void UserControl1_Enter( object sender, EventArgs e ) {
this.ActiveControl = textBox1;
}
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.