我有一个弹出来显示数据的孩子。
但是当数据发生变化时,会创建一个新表单来显示新数据。
我想关闭旧表单,所以每次数据更改时我都不会得到 5000 个表单。
创建新表单的原因是可以在其名称中显示数据的 ID。
我的代码:
String Pass; // used to get value from class and pass it to next form.
public void ShowNewCompareDiff() //object sender, EventArgs e
{
FormCompareDiff childForm = new FormCompareDiff(Pass);
childForm.MdiParent = MdiParent;
childForm.Text = "Comepare difference ";
//childForm.Close(); //Not working
//childForm = null; //Not working
childForm.Show();
}
private void dataGridViewResult_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
CompareXML Com = new CompareXML();
Pass = Com.Compare(richTextBoxSQL.Text, richTextBoxPrevSQL.Text);
ShowNewCompareDiff();
}
子窗体 FormCompareDiff:
namespace AuditIT_1
{
public partial class FormCompareDiff : Form
{
String Passed;
public FormCompareDiff(String Pass)
{
Passed = Pass;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Location = new System.Drawing.Point(836, 0); // Form Shows next to FormSchemaSearch
InitializeComponent();
}
private void FormCompareDiff_Load(object sender, EventArgs e)
{
String Pass = Passed;
CompareXML Com = new CompareXML();
webBrowserDifferences.DocumentText = Com.ResultShow(Pass);
}
}
}