怎么在自定义的类里面操作控件
如何在自定义的类里面操作控件
项目里包含From1和Class1.cs
Form1界面上一个label1,一个button1
Class1.cs
Form1.cs
------解决方案--------------------
不一定要直接操作控件,可以让a()有返回值,在button里调用a(),把返回值赋给label
------解决方案--------------------
namespace WindowsFormsApplication1
{
class Class1
{
public static void a(Label label1)
{
label1.Text="xxx";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Class1.a(label1);
}
------解决方案--------------------
项目里包含From1和Class1.cs
Form1界面上一个label1,一个button1
Class1.cs
- C# code
namespace WindowsFormsApplication1 { class Class1 { public static void a() { //我想在这里修改label1.Text } } }
Form1.cs
- C# code
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Class1.a(); } } }
------解决方案--------------------
不一定要直接操作控件,可以让a()有返回值,在button里调用a(),把返回值赋给label
------解决方案--------------------
namespace WindowsFormsApplication1
{
class Class1
{
public static void a(Label label1)
{
label1.Text="xxx";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Class1.a(label1);
}
------解决方案--------------------