110,537
社区成员
发帖
与我相关
我的任务
分享
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 Guog.Demo
{
public partial class Form1 : Form
{
private MyClass m_myClass = new MyClass();
private Form2 m_form2 = null;
public Form1()
{
InitializeComponent();
//txt1为界面上的TextBox控件
txt1.DataBindings.Add("Text", m_myClass, "Name");
}
private void button2_Click(object sender, EventArgs e)
{
if (m_form2 == null)
{
m_form2 = new Form2(m_myClass);
}
if (!m_form2.Visible)
{
m_form2.Show();
}
}
}
}
Form2.cs
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 Guog.Demo
{
public partial class Form2 : Form
{
private MyClass m_class = null;
//构造函数传参数
public Form2(MyClass myClass)
{
InitializeComponent();
m_class = myClass;
//txt1为界面上的TextBox控件
txt1.DataBindings.Add("Text", myClass, "Name");
}
//为了窗体不关闭
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
this.Hide();
base.OnClosing(e);
}
}
}
MyClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Guog.Demo
{
public class MyClass
{
public string Name { get; set; }
}
}
没有然后了...