初次点botton1时生成了控件,当我再次点botton1时,我希望是生成新的控件,但是原来的控件还存在,应该怎么办?
如下是代码
private void button1_Click(object sender, EventArgs e)
{
dbclass db1 = new dbclass();
db1.sqlConnection1.Open();
SqlCommand MyCommand = new SqlCommand("select * from patentinfo where patentid='" + this.textBox1.Text + "'", db1.sqlConnection1);
SqlDataReader MyReader = MyCommand.ExecuteReader();
if (MyReader.Read())
{
this.textBox2.Text = MyReader["patentid"].ToString();
this.textBox3.Text = MyReader["patentname"].ToString();
this.textBox4.Text = MyReader["ipc"].ToString();
this.textBox5.Text = MyReader["upc"].ToString();
this.textBox6.Text = MyReader["transteree"].ToString();
this.textBox7.Text = MyReader["inventer"].ToString();
this.textBox8.Text = MyReader["applicationdate"].ToString();
this.textBox9.Text = MyReader["publicationdate"].ToString();
this.textBox10.Text = MyReader["summary"].ToString();
int num = Convert.ToInt32(MyReader["quotenum"]);
int numb = Convert.ToInt32(MyReader["citednum"]);
string quote = MyReader["quotestr"].ToString();
string cited = MyReader["citedstr"].ToString();
string str = num + "| " + this.textBox2.Text + "|" + numb;
addcontrols(str, 404, 266);
for (int i = 0; i < num; i++)
{
addcontrols(convent(quote)[i], 154, 100 + (50 * i));
draw(254, 100 + (50 * i), 404);
}
for (int i = 0; i < numb; i++)
{
addcontrols(convent(cited)[i], 654, 100 + (50 * i));
draw(654, 100 + (50 * i), 504);
}
}
else { MessageBox.Show("查无此信息"); }
MyCommand.Dispose();
MyReader.Dispose();
db1.sqlConnection1.Close();
} private void addcontrols(string str,int x,int y)
{
System.Windows.Forms.TextBox tb = new TextBox();
panel1.Controls.Add(tb);
tb.Text =str;
tb.Location = new Point(x, y);
}
private void draw(int x, int y, int z)
{
Graphics g = this.panel1.CreateGraphics();
g.DrawLine(Pens.BlanchedAlmond, new Point(z, 275), new Point(x , y));
}
private string[] convent(string str)
{
string[] s= str.Split(',');//取出来是一个字符串数组
return s;
}
如下是代码
private void button1_Click(object sender, EventArgs e)
{
dbclass db1 = new dbclass();
db1.sqlConnection1.Open();
SqlCommand MyCommand = new SqlCommand("select * from patentinfo where patentid='" + this.textBox1.Text + "'", db1.sqlConnection1);
SqlDataReader MyReader = MyCommand.ExecuteReader();
if (MyReader.Read())
{
this.textBox2.Text = MyReader["patentid"].ToString();
this.textBox3.Text = MyReader["patentname"].ToString();
this.textBox4.Text = MyReader["ipc"].ToString();
this.textBox5.Text = MyReader["upc"].ToString();
this.textBox6.Text = MyReader["transteree"].ToString();
this.textBox7.Text = MyReader["inventer"].ToString();
this.textBox8.Text = MyReader["applicationdate"].ToString();
this.textBox9.Text = MyReader["publicationdate"].ToString();
this.textBox10.Text = MyReader["summary"].ToString();
int num = Convert.ToInt32(MyReader["quotenum"]);
int numb = Convert.ToInt32(MyReader["citednum"]);
string quote = MyReader["quotestr"].ToString();
string cited = MyReader["citedstr"].ToString();
string str = num + "| " + this.textBox2.Text + "|" + numb;
addcontrols(str, 404, 266);
for (int i = 0; i < num; i++)
{
addcontrols(convent(quote)[i], 154, 100 + (50 * i));
draw(254, 100 + (50 * i), 404);
}
for (int i = 0; i < numb; i++)
{
addcontrols(convent(cited)[i], 654, 100 + (50 * i));
draw(654, 100 + (50 * i), 504);
}
}
else { MessageBox.Show("查无此信息"); }
MyCommand.Dispose();
MyReader.Dispose();
db1.sqlConnection1.Close();
} private void addcontrols(string str,int x,int y)
{
System.Windows.Forms.TextBox tb = new TextBox();
panel1.Controls.Add(tb);
tb.Text =str;
tb.Location = new Point(x, y);
}
private void draw(int x, int y, int z)
{
Graphics g = this.panel1.CreateGraphics();
g.DrawLine(Pens.BlanchedAlmond, new Point(z, 275), new Point(x , y));
}
private string[] convent(string str)
{
string[] s= str.Split(',');//取出来是一个字符串数组
return s;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货