你写的不是很明白阿,其他的代码也写出来看看?要学会提问,不然没人回答的
最后那个单词应该是location吧?

解决方案 »

  1.   

    偶试了,这样是可以的:
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(336, 216);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(120, 48);
    this.label1.TabIndex = 0;
    this.label1.Text = "mmnnmmn";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(208, 224);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(64, 24);
    this.label2.TabIndex = 1;
    this.label2.Text = "nmnmnm";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(592, 270);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    string ls_name,ls_state;
    int i=0;
    SqlConnection sqlconn=new SqlConnection("Server=localhost;Database=werp;Integrated Security =true;user id=sa;password=sa");
    SqlCommand sqlcmd =new SqlCommand("select * from t_czy  ",sqlconn);
    SqlCommand sqlcmdcount =new SqlCommand("select count(*) from t_czy",sqlconn);
    sqlconn.Open();
    int result=(int) sqlcmdcount.ExecuteScalar();  
    SqlDataReader sqlreader=sqlcmd.ExecuteReader();
    while(sqlreader.Read()) 
    {
    i=i+1;
    ls_name=sqlreader["mc"].ToString();
    ls_state=sqlreader["state"].ToString();
    Label newLabel=CreateLable(ls_name,ls_state,i);
    this.Controls.Add(newLabel);
    MessageBox.Show(ls_name);
    };
    this.ResumeLayout(false);
    MessageBox.Show(this.Controls.Count.ToString());
    } private Label CreateLable(string name,string state,int j)  //创建lable
    {
    Label ls_labname =new Label();
    this.SuspendLayout();
    int intY=16+30 *j;
    ls_labname.Location=new System.Drawing.Point(64,intY);
    ls_labname.Size=new System.Drawing.Size(64,24);//这个值不要设得太大,否则除了第一个外其余的会看不到
    ls_labname.Text=name;
    ls_labname.Parent=this;
    if (state=="1")
    ls_labname.ForeColor=System.Drawing.Color.Red;


    ls_labname.Name=name;
    return ls_labname;
    //this.Controls.Add(ls_labname);
    //this.ResumeLayout(false);

    } }
    }