日期:2014-05-18  浏览次数:21049 次

如何从一个类 读写窗体的控件
C# code

/////form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
    }
}



C# code


///class.cs
namespace WindowsFormsApplication3
{
    class Class1
    {
        static public void test()
        {
            ////这里
            Label lab = Form1.
        }
    }
}





如何在 Class1 里 读写 Form1 中的控件属性 例如 lable 控件

请给出例子代码, 多谢

------解决方案--------------------
Label lab = Form1,我看成Label lab = New Form1了

如果是传入的就需要传入参数了

static public void test(Form1 f)
{
////这里
f.Lable1.Text = "AAA";
}

如果是Form1调用这个函数就写 Class1.test(this);