I'm creating 3 textbox and add to the flowlayoutpanel, but flowlayoutpanel control count 0.Why does the number of checks appear to be 0, what is the reason?
internal void Create_TextBox_Click(object sender, EventArgs e)
{
var Dynamic = sender as TextBox;
Regex regex = new Regex(@"\d+");
Match match = regex.Match(Dynamic.Name);
if (match.Success)
{
if(Dynamic.Name == "txtCash"+match.Value)
{
TextBox DynamicDataOne = fp.Controls.Find("txt" + match.Value, true)[0] as TextBox;
TextBox DynamicDataTwo = fp.Controls.Find("txtTwo" + match.Value, true)[0] as TextBox;
int _One;
int _Two;
if (int.TryParse(DynamicDataOne.Text, out _One) && int.TryParse(DynamicDataTwo.Text, out _Two))
Dynamic.Text = (_One * _Two).ToString();
}
}
}
您可以轻松地执行以下操作:
var textboxes = fp.Controls.OfType<TextBox>().Where(x=> Regex.IsMatch(x.Name, "txtCash\\d+"));
I solved the problem in this way;
string GetTextBox()
{
TextBox txt = fp.Controls.Find("txt1", true)[0] as TextBox;
return txt.Text;
}
But why can't I do it in the event?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.