C#如何訪問主窗體中的控件

通用函數的參數是主窗體類型的變量,在主程序中使用 this 做爲參數來調用,這樣就能在通用函數中直接訪問主窗體內的各個控件了。「個人論壇背景圖片輪換」是項目的namespace,Form1就是主窗體類。 主程序:               private void button1_Click(object sender, EventArgs e)               {                       if (ifparaok(this))                       {                                 。。。。。。                       }               } 通用函數:               public static bool ifparaok(個人論壇背景圖片輪換.Form1 mainform)               {                       bool ifok = true;                       bgimagedir = mainform.textBox1.Text;                       bbsbgimage = mainform.textBox2.Text;                       hour = Convert.ToInt32(mainform.comboBox1.SelectedItem.ToString());                       。。。。。。                       return ifok;               }
相關文章
相關標籤/搜索