- A+
所属分类:.NET技术
如果需要查看更多文章,请微信搜索公众号 csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群, 我邀请你进群! ! !
form1:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { int data= sumData(10, 25); MessageBox.Show(data.ToString()); } } }
form2:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp4 { public partial class Form1 : Form { public static int sumData(int a,int b) { return a + b; } } }
此窗体的Form2:Form 改为Form1:Form
再删除Form2.Designer.sc 和
public Form2()
{
InitializeComponent();
}
这样Form2中的代码就可以像Form1中的代码一样使用了!
运行结果: