关于动态向winform添加控件及响应事件
  举例:比如一个象qq控制面板的窗体界面(但没有用户显示),当向后台数据库读取有新的数据时(用户留言),就向界面添加一个用户和用户留言(如图下图),点击用户名联到网站回复页面。  大概样例图:(拥护1~N和留言就用label获取吧)   用户1  请问你们支持```
   用户2  我要买N82
    `
    `
    `
   用户N   你公司还有```

解决方案 »

  1.   

    可以用Label,也可以直接用LinkLabel创建之后,它们的事件都用一个方法,在那个方法里面通过参数可以得到URL,你需要在创建LinkLabel的时候把URL放在LinkLabel里面
      

  2.   

    补充
      我要解决的是如何把读取新的数据动态添加到列表中去。列表我就用listView控件
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Threading;namespace ConsoleApplication1
    {
        public class Class1 : Form
        {
            private int top;
            private const int left = 200;        // 初始化窗口
            public Class1()
            {
                top = 0;            this.Size = new Size(640, 480);            Button button = new Button();
                button.Location = new Point(20, 20);
                button.ClientSize = new Size(100, 20);
                button.Text = "AddButton";
                button.Click += new EventHandler(AddButton);
                this.Controls.Add(button);
            }        // 动态添加控件-按钮
            public void AddButton(object sender, EventArgs e)
            {
                Button button = new Button();
                button.Size = new Size(100, 20);
                button.Location = new Point(left,top);
                button.Text = "Button" + this.Controls.Count.ToString();
                button.Click += new EventHandler(Button_Click);
                this.Controls.Add(button);
                top += (20 + 10);
            }        // 动态添加的按钮的单击事件处理程序
            public void Button_Click(object sender, EventArgs e)
            {
                // 可以根据建值进行处理
                MessageBox.Show(((Button)sender).Text);
            }
        }    public class MyProgram
        {
            public static void Main()
            {
                Class1 class1 = new Class1();
                Application.Run(class1);            
            }
        }
    }
      

  4.   

    你要动态添加listview的数据
    有listview.add(new listitem(string value, string text))
    value 和text的参数位置我是乱写的具体你自己看看