Setting focus on a control

J

Jose Rodriguez

Hi, I have the following situation. I have a main form with two panels
divided by a splitter. The first panel has some links that when clicked, add
forms into the second panel. I am trying to set focus in the first textbox
in those forms. I have tried Textbox1.focus on the form_activated event, I
have tried setting the focus immediately after the InitializeComponent
statement to no avail. When the form is loaded, I have added
Form1.Activate(), again no solution, The form that is always active is the
main form, not the loaded form inside the panel, even though I am inputting
text etc. Has anybody run into this problem? any suggestions/hacks? any help
is appreciated. thanks

Jose
 
G

Guest

I believe the vb fix would be:
me.activecontrol = textbob1

and the c# is:
this.activecontrol = textbox1
 
J

Jose Rodriguez

I tried it but it didn't quite work, but having said that, you put me in the
right track, the solution was to add this in the frmMain so the form within
the container panel becomes the activecontrol

this.ActiveControl = this.Controls[2].Controls[0]; //Control[0] is a form

I am sure there is a more elegant way...but I'll hit that later. Thanks for
your help!

Jose
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top