110,536
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.FEventDelegate_AllFloorError += new Form2.FDelegate_AllFloorError(FEventDelegate_AllFloorError);
frm.Show();
}
void FEventDelegate_AllFloorError(string ErrorMsg)
{
textBox1.Text = textBox1.Text + ErrorMsg;
}
form2代码
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public delegate void FDelegate_AllFloorError(string ErrorMsg);
public event FDelegate_AllFloorError FEventDelegate_AllFloorError;
private void button1_Click(object sender, EventArgs e)
{
FEventDelegate_AllFloorError("abc"+"\r\n");
}
}
Class A{
private Form f;
public A (Form f){
this.f = f;
}
public void otherFunl(){
f.Textbox.text = "xxx";//这样就不行。访问不到到Textbox
f.setText();//直接调用我在form中写的方法也不行。
}
}
Form 改成 Form1 改成你写的窗体的那个类名称
private System.Windows.Forms.Button button5;
public System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button6;
Class A{
private Form f;
public A (Form f){
this.f = f;
}
public void otherFunl(){
f.Textbox.text = "xxx";//这样就不行。访问不到到Textbox
f.setText();//直接调用我在form中写的方法也不行。
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
A a = new A(this);
}
}
class A
{
public A(Form1 from1)
{
from1.txtBox.Text = "Yes!";
}
}
A a = new A(this);
然后在A类中想修改Form中的Textbox。这样为什么不行啊?
public class A{
public void xxx(){
//我希望能在这里修改到form控件中的Textbox
}
}
[/quote]
我给你写的例子 就是你要的啊
public class A{
public void xxx(){
//我希望能在这里修改到form控件中的Textbox
}
}