2020年11月24日星期二

C# 代码分两个窗体编写

如果需要查看更多文章,请微信搜索公众号 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中的代码一样使用了!

 

运行结果:

 









原文转载:http://www.shaoqun.com/a/493004.html

福茂:https://www.ikjzd.com/w/1633

adore:https://www.ikjzd.com/w/2202

邓白氏集团:https://www.ikjzd.com/w/582


如果需要查看更多文章,请微信搜索公众号csharp编程大全,需要进C#交流群群请加微信z438679770,备注进群,我邀请你进群!!!form1:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;u
bonanza:bonanza
敦煌网:敦煌网
海南万泉河的水干净吗?万泉河漂流好不好?:海南万泉河的水干净吗?万泉河漂流好不好?
浙江鲜为人知的旅行地 你知道几个(组图):浙江鲜为人知的旅行地 你知道几个(组图)
亚马逊全球开店"跨境峰会"内容分享!:亚马逊全球开店"跨境峰会"内容分享!

没有评论:

发表评论