我有MDI>> Form1>> Form2和form1我使用组件计时器来检查Form2中的值。
Form1中
namespace Purchasing
{
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
private string find_code;
public string _code
{
set { find_code = value.ToUpper(); }
}
public XtraForm1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XtraForm2 frm = new XtraForm2();
frm.ShowDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (find_code != null)
{
textBox1.Text = find_code;
find_code = null;
}
}
}
}
窗体2
namespace Purchasing
{
public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
{
public XtraForm2()
{
InitializeComponent();
}
private void XtraForm2_Click(object sender, EventArgs e)
{
XtraForm1 frm = new XtraForm1();
frm._code = "123";
Close();
}
}
}
但是在我运行此程序后,123无法在textbox1中显示,如果是Messagebox.Show(find_code)
,则会显示该值。 mycode出了什么问题?
答案 0 :(得分:0)
将XtraForm1添加为XtraForm2的成员,如下所述:
public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
{
public XtraForm1 frm1;
public XtraForm2()
{
InitializeComponent();
}
private void XtraForm2_Click(object sender, EventArgs e)
{
frm1._code = "123";
Close();
}
}
在XtraForm1类中,将上面添加的成员设置为:
private void button1_Click(object sender, EventArgs e)
{
XtraForm2 frm = new XtraForm2();
frm.frm1 = this;
frm.ShowDialog();
}
答案 1 :(得分:0)
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
public XtraForm1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XtraForm2 frm = new XtraForm2();
frm.ShowDialog();
textBox1.Text = frm.Code;
}
}
namespace Purchasing
{
public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
{
public string _code = string.Empty;
public string Code
{
get {
return _code;
}
}
public XtraForm2()
{
InitializeComponent();
}
private void XtraForm2_Click(object sender, EventArgs e)
{
_code= "123";
this.Close();
}
}
}
答案 2 :(得分:0)
在您的XtraForm2_中,您创建了一个新表单,然后您无法访问旧表单中的值。
你可以测试一下(未测试但可能有效)
<强>窗体2 强>
namespace Purchasing
{
public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
{
public string Code { get; set; }
public XtraForm2()
{
InitializeComponent();
}
private void XtraForm2_Click(object sender, EventArgs e)
{
Code = "123";
}
}
}
<强> Form1中强>
namespace Purchasing
{
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
private Form _frm;
public XtraForm1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_frm = new XtraForm2();
_frm.Show();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(((XtraForm2 )_frm).Code))
{
textBox1.Text = ((XtraForm2 )_frm).Code;
((XtraForm2 )_frm).Code = null;
}
}
}
}