为什么flowlayoutpanel控件计数为0 C#
Why flowlayoutpanel controls count 0 C#
我正在创建 3 个文本框并添加到 flowlayoutpanel,但是 flowlayoutpanel 控制计数 0.Why 检查的次数似乎为 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+"));
我是这样解决问题的;
string GetTextBox()
{
TextBox txt = fp.Controls.Find("txt1", true)[0] as TextBox;
return txt.Text;
}
可是为什么我不能在活动中做到呢?
我正在创建 3 个文本框并添加到 flowlayoutpanel,但是 flowlayoutpanel 控制计数 0.Why 检查的次数似乎为 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+"));
我是这样解决问题的;
string GetTextBox()
{
TextBox txt = fp.Controls.Find("txt1", true)[0] as TextBox;
return txt.Text;
}
可是为什么我不能在活动中做到呢?