帮我看看!为什么只显示一个标签! 你写的不是很明白阿,其他的代码也写出来看看?要学会提问,不然没人回答的最后那个单词应该是location吧? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 偶试了,这样是可以的: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); } }} 关于IQueryable接口 求解... 求教 datagridview 问题 我的网站中病毒啦,急…… 关于vs2005中设置起始页的问题 高分相送!!!急,一个关于Response.Redirect下载文件的问题。 C# windows Forms Aplication新建文件运行总是提示“系统找不到指定的路径”怎么回事 C# 怎么把画在picture控件图形保存为PDF格式的文件 高手们看一下我的程序,说是登陆失败啊 vs.net的cd-key(在线等待) 神呐。。。求求我吧!!急。。。。 开发出来的东东不能运行?!
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);
} }
}