C#窗口应用程序动态代码不起作用 [英] C# window application dynamic code is not working
问题描述
Form1:
公共字符串labelText
{
get {
返回Label1.text;
}
设置{
Label1.text = value;
}
}
表格2:
(表格)frm =新表格(Form1);
frm.findcontrol(dt.Rows [0] [ControlName]。toString())。text = dt .Rows [0] [ChangeText]。toString();
以上winForm代码无效。 Form1和Form2在文件夹内(Window窗体)
我尝试过:
我有动态表格名称和标签名称。我的主要问题是我想动态更改标签名称。
Form1:
public string labelText
{
get{
return Label1.text;
}
set{
Label1.text=value;
}
}
Form2:
(Form) frm=new Form("Form1");
frm.findcontrol(dt.Rows[0]["ControlName"].toString()).text=dt.Rows[0]["ChangeText"].toString();
Above winForm code is not working. And Form1 and Form2 are inside the folder(Window Forms)
What I have tried:
I have Dynamic Form name and label name. My main issue is I want change the label name dynamically.
推荐答案
您可以使用以下内容:
You could use something like this:
foreach (System.Windows.Forms.Control ctrl in frm.Controls)
{
switch (ctrl.GetType().Name)
{
case "Button":
case "ToolStrip":
case "ToolStripMenuItem":
case "DataGridView":
Debug.Print(ctrl.Name);
break;
default:
break;
}
}
这篇关于C#窗口应用程序动态代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!