Hi Carlos,
I downloaded, compiled and ran your sample. The focus is indeed at Textbox1 *but* when I replaced it with this line: textBox2.Select(); Focus is now in Textbox2 which I believe is what you want. Please refer to my updates here: http://pastebin.com/RftBV99z Also I noted that dead code is existing in your example. If you don't intend to use them, I suggest you remove it. Refer to http://en.wikipedia.org/wiki/Dead_code for details. Thank you and regards, Benj On Nov 26, 6:23 pm, Carlos Caetano <[email protected]> wrote: > Benj, > > I create a test code and post inhttp://pastebin.com/7F4sZVEz. > > In this example i have a Textbox1 and Textbox2 in UserControl. > > In UserControl load event I set focus to Textbox2 but the focus still in > Textbox1. > > The project files of this example is in ZIP file. > > Att, > Carlos Caetano > > 2010/11/26 Benj Nunez <[email protected]> > > > > > Hello Carlos, > > > That's strange. I tested the code here on my machine and it's working. > > Are you sure you have entered the code correctly? > > > As an alternative, try using textBox1.Focus() instead of > > textBox1.Select() > > > Or better yet, post your code snippet athttp://pastebin.comso that I > > will know what > > you are doing in your code. Please provide me your link there so I can > > see it better. > > > Thanks and Regards, > > > Benj > > > On Nov 26, 12:58 am, Carlos Caetano <[email protected]> wrote: > > > Hi Benj, > > > > I try this solution but dont work. You have another idea? > > > > Tks, > > > Carlos > > > > 2010/11/25 Benj Nunez <[email protected]> > > > > > Hi Carlos, > > > > > To set focus to a textbox within the UserControl, add a line like this > > > > under the UserControl's Load event like so: > > > > > private void UserControlXXX_Load(object sender, EventArgs e) > > > > { > > > > textBox1.Select(); > > > > } > > > > > Regards, > > > > > Benj > > > > > On Nov 25, 12:13 pm, Carlos Caetano <[email protected]> wrote: > > > > > Hi, > > > > > > The Benj's solution works for me, but when I load a UserControl in a > > > > Panel i > > > > > cant set Focus in textbox inside the UserControl. > > > > > > Please, help me again. > > > > > > Carlos Caetano > > > > > > 2010/11/22 Arsalan Tamiz <[email protected]> > > > > > > > As far as I understand, > > > > > > > 1) You have 2 UserControls uc1 and uc2 > > > > > > 2) uc1 has a Button on it > > > > > > 3) You have added uc1 in a Panel Programmatically > > > > > > 4) You want uc1 to be removed from Panel, if uc1's button is > > pressed > > > > > > 5) And on the same point you want uc2 to be added in Panel > > > > > > > I think that Button should NOT be on uc1, rather it should be on > > Panel, > > > > in > > > > > > this way you can easily remove and add controls. Plus in this > > scenario, > > > > I > > > > > > think the show/hide technique is a bit better than adding and > > removing > > > > > > controls. > > > > > > > Anyway if you want the same thing to be done then heres how you > > should > > > > do, > > > > > > > Benj's Idea is also a valid one i.e. add a reference of Panel in > > uc1. > > > > But > > > > > > this is a bit less flexible approach. Because what if uc1 is being > > > > added in > > > > > > some other container control? > > > > > > > So the better flexible approach is that uc1 should raise some event > > > > like > > > > > > "my button has been clicked do whatever you would like to do". In > > this > > > > way > > > > > > the parent will be responsible for listening that event and once > > that > > > > event > > > > > > gets occurred. Then you can remove the uc1 and add uc2 within > > parent > > > > > > control. > > > > > > > On Sun, Nov 21, 2010 at 7:25 AM, Carlos Caetano < > > > > [email protected]>wrote: > > > > > > >> Hi, > > > > > > >> I have a Panel named *panel1 *and two User Controls named *uc1 > > *and > > > > *uc2* > > > > > >> . > > > > > > >> I add UserControl in Panel with de following command: > > > > > > >> uc1 myuc1 = new uc1(); > > > > > >> panel1.Controls.Add(myuc1); > > > > > > >> How can I remove the User Control *uc1 *from panel and add *uc2 > > *with > > > > > >> event from button inside *uc1*. > > > > > > >> Tks, And sorry for my English* > > > > > >> * > > > > > >> -- > > > > > >> Carlos Caetano > > > > > > -- > > > > > Carlos Caetano > > > > -- > > > Carlos Caetano > > -- > Carlos Caetano > > Teste.rar > 49KViewDownload
