国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現窗口之間的傳值

2020-01-24 01:47:57
字體:
來源:轉載
供稿:網友

為了解決在多個窗口之間的傳值問題,我們可以通過設置靜態類和靜態變量的辦法來實現窗口間值的傳遞

窗體一代碼

//窗體1的代碼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 WindowsFormsApplication1{  public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }         private void button1_Click(object sender, EventArgs e)    {      sharedclass.sharedvalue = textBox1.Text.ToString(); //靜態變量的用法:類名.變量名 賦值給靜態變量      Form2 frm2 = new Form2();      frm2.Show();         }  }  public static class sharedclass //在命名空間設置一個靜態類sharedclass,不要放置在form1前面  {    public static string sharedvalue; //設置一個靜態變量sharedvalue  }}

窗體2代碼

//窗體2的代碼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 WindowsFormsApplication1{  public partial class Form2 : Form  {    public Form2()    {      InitializeComponent();      textBox1.Text = sharedclass.sharedvalue; //靜態變量傳入給窗口2的textBox    }  }}

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博爱县| 清原| 高邑县| 金溪县| 肥城市| 丰城市| 洞头县| 廉江市| 苍梧县| 都兰县| 福贡县| 定边县| 察隅县| 蓬安县| 于田县| 鄂州市| 敖汉旗| 揭西县| 盐山县| 柳江县| 石屏县| 三河市| 开原市| 遂平县| 景泰县| 阳西县| 云梦县| 明光市| 岢岚县| 宁晋县| 乌拉特后旗| 德令哈市| 曲阳县| 区。| 忻州市| 梧州市| 郁南县| 咸丰县| 莱阳市| 尚志市| 蛟河市|