若是須要查看更多文章,請微信搜索公衆號 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:spa
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 code
再刪除Form2.Designer.sc 和orm
public Form2() { InitializeComponent(); }
這樣Form2中的代碼就能夠像Form1中的代碼同樣使用了!blog
運行結果:ip