Events with Dynamically created controls.

D

Dale Williams

Everyone:

I have a WinForm in which I dynamically create tabs based on some user
input. Inside those tabs are some text boxes for data. I can do
everything but fire events properly. I have a click event for one of
the text boxes on each tab. When I click on the text box the event is
fired but I don't know how to check which text box on which tab has
been fired.

Thank you for the help.

Sincerely,
Dale Williams

I have the following code to add the text box to the tab:

// Add text box to display formulas, etc.
TextBox l_objTB = new TextBox();
l_objTB.Name = "txt-" + l_objSubRow["RFQQuantityId"].ToString() +
"-" + l_objSubRow["RecType"].ToString();
l_objTB.Enabled = true;
l_objTB.Width = 250;
l_objTB.Top = l_objSubTabCon.Top;
l_objTB.Click +=new EventHandler(l_objTB_Click);
l_objSubTabCon.TabPages[l_lSubLoop].Controls.Add(l_objTB);


I have the following click event for the text box.
private void l_objTB_Click(object sender, EventArgs e)
{
e.ToString();
}
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Dale,
Reference to the text box comes in the sender parameter of the event
handler. To find out the page use TextBox.Parent property.
 

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