假设我在添加一个winodw窗体,在上面拖了一个TextBox控件 我在form_load中给他赋了个值"测试1"; 如何在另一个类中修改这个TextBox值。
我在网上查了用到委托和事件,但是还是不行,主要是传递这个TextBox控件,
您好
參考以下代碼
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MyClass myClass = new MyClass(this.textBox1); myClass.ChangeTextBox(); } } public class MyClass { TextBox _textBox1; public MyClass(TextBox textBox1) { _textBox1 = textBox1; } public void ChangeTextBox() { _textBox1.Text = "TEST"; } } }