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

Reply via email to