先建一个cs文件
using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication1
{
public class Class1
{
private double TXT1;
public double txt1
{
get { return TXT1; }
set { TXT1 = value; }
}
private double TXT2;
public double txt2
{
get { return TXT2; }
set { TXT2 = value; }
}
private double SUM;
public double Math()
{
SUM = TXT1 + TXT2;
return SUM;
}
}
}
Button的代码
Class1 Class = new Class1();
Class.txt1 = double.Parse(textBox1.Text);
Class.txt2 = double.Parse(textBox2.Text);
textBox3.Text = Class.Math().ToString() ;
public button_submit()
{textBox3.text=textBox1.text.trim()+textBox2.text.trim();}
窗体类名.控件名 记得要把控件设成public
控件要是public的类型
窗体名.控件名
3楼的好点 1 2楼影响数据的封装
窗体类名.控件名 记得要把控件设成public