C#-Form2值到Form1
我在传递值时遇到问题从表格2(citacao)输入到表格1(委托人) Principal.cs(表格1) Citacao.cs(表格2) 但当我点击按钮时,什么也没发生,值没有插入到richedit中,我喜欢它 我已经在表单上有了它(将DataGrid传递给ComboBox) 表格1(委托人) 表格2(西塔岛)C#-Form2值到Form1,c#,winforms,C#,Winforms,我在传递值时遇到问题从表格2(citacao)输入到表格1(委托人) Principal.cs(表格1) Citacao.cs(表格2) 但当我点击按钮时,什么也没发生,值没有插入到richedit中,我喜欢它 我已经在表单上有了它(将DataGrid传递给ComboBox) 表格1(委托人) 表格2(西塔岛) 让我们看看我是否理解你的处境:) 将表单1中的变量声明为类变量 private citacao cita; 然后在按钮按下事件中初始化它 private void barBut
让我们看看我是否理解你的处境:) 将表单1中的变量声明为类变量
private citacao cita;
然后在按钮按下事件中初始化它
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
cita = new citacao(this);
// subscribe to the closing event
cita.FormClosing += form_FormClosing;
cita.Show();
}
// when Form 2 will be closed you can execute your important line in the event
void form_FormClosing(object sender, FormClosingEventArgs e)
{
// BUT! you have to use the variable name!
richEditControl1.Document.AppendText(cita.valor_edit[0]);
}
编辑:
查看完整代码后,确定:
请卸下按钮3!整个代码是:
private void button3_Click(object sender, EventArgs e)
{
cita = new citacao(this);
richEditControl1.Document.AppendText(citacao.valor_edit); // this line is the problem!
}
函数AppendText
可能需要一个string
作为参数,您可以给出整个数组!
如果您在Form1/principal中订阅了关闭事件,并且还实现了
事件发生后,一旦表单2从屏幕上消失,您的数据将自动传输:)这一行是什么时候:
richEditControl1.Document.AppendText(citacao.valor_edit[0])代码>执行?何时必须在表格1中显示这些值?在表格2关闭时运行。尝试编译错误3时,参数1:无法从'string[]转换为'string'C:\Users\RCA\Desktop\ABTN\u Format\abontfacil\abontfacil\princil.cs 93 50 abontfacil
,错误1非静态字段、方法需要对象引用,或属性“ABNTFacil.citacao.valor\u edit”C:\Users\RCA\Desktop\ABTN\u Format\ABNTFacil\ABNTFacil\principal.cs 93 50 ABNTFacil
。我也试过这个,但不起作用citacao-cita=new-citacao(这个);richEditControl1.Document.AppendText(cita.valor_编辑)代码>你可以发布更多的代码吗?很难在断开连接的代码之间跳转并尝试找出程序流程,所以你在表1中有表2的关闭事件,对吗?你的错误来自这一行richEditControl1.Document.AppendText(citacao.valor_edit[0])代码>因为您使用类名(citacao),所以编译器会查找名为valor_edit
的静态变量,但它不是静态错误3非静态字段、方法需要对象引用,或属性'ABNTFacil.citacao.valor_edit'C:\Users\RCA\Desktop\ABTN_Format\ABNTFacil\ABNTFacil\princil.cs 105 50 ABNTFacil错误2参数1:无法从'string[]'转换为'string'C:\Users\RCA\Desktop\ABTN_Format\ABNTFacil\ABNTFacil\princil.cs 105 50 ABNTFacil之前的相同错误-在这里可以看到所有代码。。。。citação.cs(),principal.cs()@CarlosIyu在调用子窗体上的Show()
之前,将父窗体作为其构造函数中的参数传递给子窗体,并将其存储在实例变量中。@CarlosIyu我编辑了我的答案。感谢您访问整个代码,信息使问题解决变得更容易:)@CarlosIyu很高兴我能提供帮助。事件确实值得深入研究。:)
public citacao(principal gridForm)
{
InitializeComponent();
frm1 = gridForm;
}
// LOAD ALL FONTS (Referencias);
private void citacao_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
foreach (DataGridViewRow row in frm1.DataGridView1.Rows)
{
comboBox1.Items.Add(row.Cells[0].Value.ToString());
}
comboBox1.SelectedIndex = 0;
}
private citacao cita;
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
cita = new citacao(this);
// subscribe to the closing event
cita.FormClosing += form_FormClosing;
cita.Show();
}
// when Form 2 will be closed you can execute your important line in the event
void form_FormClosing(object sender, FormClosingEventArgs e)
{
// BUT! you have to use the variable name!
richEditControl1.Document.AppendText(cita.valor_edit[0]);
}
private void button3_Click(object sender, EventArgs e)
{
cita = new citacao(this);
richEditControl1.Document.AppendText(citacao.valor_edit); // this line is the problem!
}