[英]Why flowlayoutpanel controls count 0 C#
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? 我正在创建3个文本框并添加到flowlayoutpanel,但是flowlayoutpanel控件的计数为0。为什么检查次数似乎为0,这是什么原因?
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? 但是,为什么我不能这样做呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.