Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UserControl Focus Problem
Message
De
18/05/2009 23:06:08
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01398893
Message ID:
01400559
Vues:
44
>Thank Bonnie. Worked fine.

Cool! =0)

~~Bonnie


>
>
>
>>Actually, I'll add to my last reply with some more code. I have two classes for Tab stuff ... we don't typically use Tab Controls/Pages in our apps, but one non-standard set of forms needed to use them for some UI-compatibility with an old app.
>>
>>Anyway, so I created a BBTabControl class and a BBTabPage class. Each of those has a GotFocusHandler that does the following:
>>
>>In the BBTabControl
>>
>>protected virtual void GotFocusHandler(object sender, EventArgs e)
>>{
>>	this.TabPages[this.SelectedIndex].Focus();
>>}
>>
>>
>>In the BBTabPage
>>
>>protected virtual void GotFocusHandler(object sender, EventArgs e)
>>{
>>	if (this.Controls.Count > 0)
>>	{
>>		Control o = this.GetNextControl(this, true);
>>		while (o.Controls.Count > 0)
>>		{
>>			o = o.GetNextControl(o, true);
>>		}
>>		o.Focus();
>>	}
>>}
>>
>>
>>Hope that helps a bit.
>>
>>~~Bonnie
>>
>>
>>>I am adding a user control to a TabPage at runtime. The control has a textbox on it. I cannot seem to get the focus to go into the text box.
>>>
>>>I have:
>>>
>>>
>>>// Set the tag of the page to the enum
>>>oNewPage.Tag = csApplication.Panes.ship_items;
>>>
>>>// Create the usercontrol and call the setup method on it
>>>crlShipItems oShipItems = new crlShipItems();
>>>oShipItems.Setup();
>>>
>>>// Add the user control to the tab
>>>tabPages.TabPages[iPage].Controls.Add(oShipItems);
>>>oShipItems.Dock = DockStyle.Fill;
>>>
>>>// Set the focus on the control
>>>oShipItems.Select();
>>>
>>>
>>>Then in the control's enter event I have:
>>>
>>>
>>>private void crlShipItems_Enter(object sender, EventArgs e)
>>>{
>>>    txtPartNo.Focus();
>>>}
>>>
>>>
>>>The problem is that the textbox isn't getting the focus. The event fires, the focus just doesn't set.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform