public class Form1 : Form
{
public int Count; //某个方法里
protected void Method()
{
Class1 c = new Class1();
c.AddLabel(this,out Count);
}
}
public class Class1
{
public void AddLabel(Form f,out int count)
{
count++;
Label l = new Label();
l.Name = "label" + count;
l.Text = "****";
//继续为l其他属性赋值
f.Controls.Add(l);
}
}
当我双击 lable的时候打开FROM2 这个事件怎么写?
{
public int Count; //某个方法里
protected void Method()
{
Class1 c = new Class1();
c.AddLabel(this,out Count);
}
}
public class Class1
{
public void AddLabel(Form f,out int count)
{
count++;
Label l = new Label();
l.Name = "label" + count;
l.Text = "****";
//继续为l其他属性赋值
f.Controls.Add(l);
}
}
当我双击 lable的时候打开FROM2 这个事件怎么写?
{
public void AddLabel(Form f, out int count)
{
count++;
Label l = new Label();
l.Name = "label" + count;
l.Text = "****";
l.MouseDoubleClick += new MouseEventHandler(l_MouseDoubleClick);
//继续为l其他属性赋值
f.Controls.Add(l);
} void l_MouseDoubleClick(object sender, MouseEventArgs e)
{
Form1 form = new Form1();
form.Show();
}
}
{
public void AddLabel(Form f, ref int count)
{
count++;
Label l = new Label();
l.Name = "label" + count;
l.Text = "****";
//继续为l其他属性赋值
f.Controls.Add(l);
l.DoubleClick += new EventHandler(l_DoubleClick);
} private void l_DoubleClick(object sender, EventArgs e)
{
Form2 o = new Form2();
o.Show();
}
}