求C#自动生成控件的样例,急~~~
求一个C#自动生成控件的样例,最好带有从数据库中读取信息的,要完整的代码,因为要做项目,初学不会,还请大家帮助是个自定义控件,里面的例如按钮啥的,是通过代码的编写生成的,...
求一个C#自动生成控件的样例,最好带有从数据库中读取信息的,要完整的代码,因为要做项目,初学不会,还请大家帮助
是个自定义控件,里面的例如按钮啥的,是通过代码的编写生成的,并不是手动直接加载的 展开
是个自定义控件,里面的例如按钮啥的,是通过代码的编写生成的,并不是手动直接加载的 展开
3个回答
展开全部
vs自动生成的就是咯。。
namespace MyComputer
{
partial class frmMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lsvComputer = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.lblType = new System.Windows.Forms.Label();
this.lblName = new System.Windows.Forms.Label();
this.lblBrand = new System.Windows.Forms.Label();
this.lblHradDisk = new System.Windows.Forms.Label();
this.lblMemory = new System.Windows.Forms.Label();
this.lblCPU = new System.Windows.Forms.Label();
this.lblHostType = new System.Windows.Forms.Label();
this.lblBattery = new System.Windows.Forms.Label();
this.lblMonitor = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lsvComputer);
this.groupBox1.Location = new System.Drawing.Point(4, 10);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(608, 260);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "电脑列表";
//
// lsvComputer
//
this.lsvComputer.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.lsvComputer.FullRowSelect = true;
this.lsvComputer.GridLines = true;
this.lsvComputer.Location = new System.Drawing.Point(9, 21);
this.lsvComputer.Name = "lsvComputer";
this.lsvComputer.Size = new System.Drawing.Size(590, 222);
this.lsvComputer.TabIndex = 0;
this.lsvComputer.UseCompatibleStateImageBehavior = false;
this.lsvComputer.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "型号名称";
this.columnHeader1.Width = 90;
//
// columnHeader2
//
this.columnHeader2.Text = "品牌";
this.columnHeader2.Width = 93;
//
// columnHeader3
//
this.columnHeader3.Text = "CPU";
this.columnHeader3.Width = 94;
//
// columnHeader4
//
this.columnHeader4.Text = "内存";
this.columnHeader4.Width = 110;
//
// columnHeader5
//
this.columnHeader5.Text = "硬盘";
this.columnHeader5.Width = 96;
//
// columnHeader6
//
this.columnHeader6.Text = "显示器";
this.columnHeader6.Width = 100;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.lblHostType);
this.groupBox2.Controls.Add(this.lblBattery);
this.groupBox2.Controls.Add(this.lblMonitor);
this.groupBox2.Controls.Add(this.lblHradDisk);
this.groupBox2.Controls.Add(this.lblMemory);
this.groupBox2.Controls.Add(this.lblCPU);
this.groupBox2.Controls.Add(this.lblBrand);
this.groupBox2.Controls.Add(this.lblName);
this.groupBox2.Controls.Add(this.lblType);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(4, 277);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(608, 122);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "电脑详细信息";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(31, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 12);
this.label1.TabIndex = 0;
this.label1.Text = "类型";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(31, 54);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(31, 12);
this.label2.TabIndex = 0;
this.label2.Text = "型号";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.Location = new System.Drawing.Point(31, 84);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(31, 12);
this.label3.TabIndex = 0;
this.label3.Text = "品牌";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label4.Location = new System.Drawing.Point(237, 84);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(31, 12);
this.label4.TabIndex = 3;
this.label4.Text = "硬盘";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.Location = new System.Drawing.Point(237, 54);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(31, 12);
this.label5.TabIndex = 2;
this.label5.Text = "内存";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.Location = new System.Drawing.Point(237, 26);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(26, 12);
this.label6.TabIndex = 1;
this.label6.Text = "CPU";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label7.Location = new System.Drawing.Point(414, 84);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(57, 12);
this.label7.TabIndex = 6;
this.label7.Text = "机箱类型";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label8.Location = new System.Drawing.Point(440, 54);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(31, 12);
this.label8.TabIndex = 5;
this.label8.Text = "电池";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label9.Location = new System.Drawing.Point(414, 26);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(57, 12);
this.label9.TabIndex = 4;
this.label9.Text = "显示大小";
//
// lblType
//
this.lblType.AutoSize = true;
this.lblType.Location = new System.Drawing.Point(78, 26);
this.lblType.Name = "lblType";
this.lblType.Size = new System.Drawing.Size(0, 12);
this.lblType.TabIndex = 7;
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(78, 54);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(0, 12);
this.lblName.TabIndex = 7;
//
// lblBrand
//
this.lblBrand.AutoSize = true;
this.lblBrand.Location = new System.Drawing.Point(78, 84);
this.lblBrand.Name = "lblBrand";
this.lblBrand.Size = new System.Drawing.Size(0, 12);
this.lblBrand.TabIndex = 7;
//
// lblHradDisk
//
this.lblHradDisk.AutoSize = true;
this.lblHradDisk.Location = new System.Drawing.Point(281, 84);
this.lblHradDisk.Name = "lblHradDisk";
this.lblHradDisk.Size = new System.Drawing.Size(0, 12);
this.lblHradDisk.TabIndex = 10;
//
// lblMemory
//
this.lblMemory.AutoSize = true;
this.lblMemory.Location = new System.Drawing.Point(281, 54);
this.lblMemory.Name = "lblMemory";
this.lblMemory.Size = new System.Drawing.Size(0, 12);
this.lblMemory.TabIndex = 9;
//
// lblCPU
//
this.lblCPU.AutoSize = true;
this.lblCPU.Location = new System.Drawing.Point(281, 26);
this.lblCPU.Name = "lblCPU";
this.lblCPU.Size = new System.Drawing.Size(0, 12);
this.lblCPU.TabIndex = 8;
//
// lblHostType
//
this.lblHostType.AutoSize = true;
this.lblHostType.Location = new System.Drawing.Point(489, 84);
this.lblHostType.Name = "lblHostType";
this.lblHostType.Size = new System.Drawing.Size(0, 12);
this.lblHostType.TabIndex = 13;
//
// lblBattery
//
this.lblBattery.AutoSize = true;
this.lblBattery.Location = new System.Drawing.Point(489, 54);
this.lblBattery.Name = "lblBattery";
this.lblBattery.Size = new System.Drawing.Size(0, 12);
this.lblBattery.TabIndex = 12;
//
// lblMonitor
//
this.lblMonitor.AutoSize = true;
this.lblMonitor.Location = new System.Drawing.Point(489, 26);
this.lblMonitor.Name = "lblMonitor";
this.lblMonitor.Size = new System.Drawing.Size(0, 12);
this.lblMonitor.TabIndex = 11;
//
// button1
//
this.button1.Location = new System.Drawing.Point(324, 420);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "详细";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(417, 420);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "打印";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(512, 420);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "CloseMe";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(615, 455);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Computer";
this.Load += new System.EventHandler(this.frmMain_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListView lsvComputer;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblHostType;
private System.Windows.Forms.Label lblBattery;
private System.Windows.Forms.Label lblMonitor;
private System.Windows.Forms.Label lblHradDisk;
private System.Windows.Forms.Label lblMemory;
private System.Windows.Forms.Label lblCPU;
private System.Windows.Forms.Label lblBrand;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Label lblType;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}
namespace MyComputer
{
partial class frmMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lsvComputer = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.lblType = new System.Windows.Forms.Label();
this.lblName = new System.Windows.Forms.Label();
this.lblBrand = new System.Windows.Forms.Label();
this.lblHradDisk = new System.Windows.Forms.Label();
this.lblMemory = new System.Windows.Forms.Label();
this.lblCPU = new System.Windows.Forms.Label();
this.lblHostType = new System.Windows.Forms.Label();
this.lblBattery = new System.Windows.Forms.Label();
this.lblMonitor = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lsvComputer);
this.groupBox1.Location = new System.Drawing.Point(4, 10);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(608, 260);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "电脑列表";
//
// lsvComputer
//
this.lsvComputer.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.lsvComputer.FullRowSelect = true;
this.lsvComputer.GridLines = true;
this.lsvComputer.Location = new System.Drawing.Point(9, 21);
this.lsvComputer.Name = "lsvComputer";
this.lsvComputer.Size = new System.Drawing.Size(590, 222);
this.lsvComputer.TabIndex = 0;
this.lsvComputer.UseCompatibleStateImageBehavior = false;
this.lsvComputer.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "型号名称";
this.columnHeader1.Width = 90;
//
// columnHeader2
//
this.columnHeader2.Text = "品牌";
this.columnHeader2.Width = 93;
//
// columnHeader3
//
this.columnHeader3.Text = "CPU";
this.columnHeader3.Width = 94;
//
// columnHeader4
//
this.columnHeader4.Text = "内存";
this.columnHeader4.Width = 110;
//
// columnHeader5
//
this.columnHeader5.Text = "硬盘";
this.columnHeader5.Width = 96;
//
// columnHeader6
//
this.columnHeader6.Text = "显示器";
this.columnHeader6.Width = 100;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.lblHostType);
this.groupBox2.Controls.Add(this.lblBattery);
this.groupBox2.Controls.Add(this.lblMonitor);
this.groupBox2.Controls.Add(this.lblHradDisk);
this.groupBox2.Controls.Add(this.lblMemory);
this.groupBox2.Controls.Add(this.lblCPU);
this.groupBox2.Controls.Add(this.lblBrand);
this.groupBox2.Controls.Add(this.lblName);
this.groupBox2.Controls.Add(this.lblType);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label8);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(4, 277);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(608, 122);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "电脑详细信息";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(31, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 12);
this.label1.TabIndex = 0;
this.label1.Text = "类型";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(31, 54);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(31, 12);
this.label2.TabIndex = 0;
this.label2.Text = "型号";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.Location = new System.Drawing.Point(31, 84);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(31, 12);
this.label3.TabIndex = 0;
this.label3.Text = "品牌";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label4.Location = new System.Drawing.Point(237, 84);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(31, 12);
this.label4.TabIndex = 3;
this.label4.Text = "硬盘";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.Location = new System.Drawing.Point(237, 54);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(31, 12);
this.label5.TabIndex = 2;
this.label5.Text = "内存";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.Location = new System.Drawing.Point(237, 26);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(26, 12);
this.label6.TabIndex = 1;
this.label6.Text = "CPU";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label7.Location = new System.Drawing.Point(414, 84);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(57, 12);
this.label7.TabIndex = 6;
this.label7.Text = "机箱类型";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label8.Location = new System.Drawing.Point(440, 54);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(31, 12);
this.label8.TabIndex = 5;
this.label8.Text = "电池";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label9.Location = new System.Drawing.Point(414, 26);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(57, 12);
this.label9.TabIndex = 4;
this.label9.Text = "显示大小";
//
// lblType
//
this.lblType.AutoSize = true;
this.lblType.Location = new System.Drawing.Point(78, 26);
this.lblType.Name = "lblType";
this.lblType.Size = new System.Drawing.Size(0, 12);
this.lblType.TabIndex = 7;
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(78, 54);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(0, 12);
this.lblName.TabIndex = 7;
//
// lblBrand
//
this.lblBrand.AutoSize = true;
this.lblBrand.Location = new System.Drawing.Point(78, 84);
this.lblBrand.Name = "lblBrand";
this.lblBrand.Size = new System.Drawing.Size(0, 12);
this.lblBrand.TabIndex = 7;
//
// lblHradDisk
//
this.lblHradDisk.AutoSize = true;
this.lblHradDisk.Location = new System.Drawing.Point(281, 84);
this.lblHradDisk.Name = "lblHradDisk";
this.lblHradDisk.Size = new System.Drawing.Size(0, 12);
this.lblHradDisk.TabIndex = 10;
//
// lblMemory
//
this.lblMemory.AutoSize = true;
this.lblMemory.Location = new System.Drawing.Point(281, 54);
this.lblMemory.Name = "lblMemory";
this.lblMemory.Size = new System.Drawing.Size(0, 12);
this.lblMemory.TabIndex = 9;
//
// lblCPU
//
this.lblCPU.AutoSize = true;
this.lblCPU.Location = new System.Drawing.Point(281, 26);
this.lblCPU.Name = "lblCPU";
this.lblCPU.Size = new System.Drawing.Size(0, 12);
this.lblCPU.TabIndex = 8;
//
// lblHostType
//
this.lblHostType.AutoSize = true;
this.lblHostType.Location = new System.Drawing.Point(489, 84);
this.lblHostType.Name = "lblHostType";
this.lblHostType.Size = new System.Drawing.Size(0, 12);
this.lblHostType.TabIndex = 13;
//
// lblBattery
//
this.lblBattery.AutoSize = true;
this.lblBattery.Location = new System.Drawing.Point(489, 54);
this.lblBattery.Name = "lblBattery";
this.lblBattery.Size = new System.Drawing.Size(0, 12);
this.lblBattery.TabIndex = 12;
//
// lblMonitor
//
this.lblMonitor.AutoSize = true;
this.lblMonitor.Location = new System.Drawing.Point(489, 26);
this.lblMonitor.Name = "lblMonitor";
this.lblMonitor.Size = new System.Drawing.Size(0, 12);
this.lblMonitor.TabIndex = 11;
//
// button1
//
this.button1.Location = new System.Drawing.Point(324, 420);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "详细";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(417, 420);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "打印";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(512, 420);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "CloseMe";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(615, 455);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Computer";
this.Load += new System.EventHandler(this.frmMain_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListView lsvComputer;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblHostType;
private System.Windows.Forms.Label lblBattery;
private System.Windows.Forms.Label lblMonitor;
private System.Windows.Forms.Label lblHradDisk;
private System.Windows.Forms.Label lblMemory;
private System.Windows.Forms.Label lblCPU;
private System.Windows.Forms.Label lblBrand;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Label lblType;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}
展开全部
你可以在百度上搜“动态控件”或者是“代码控件”,下面一段程序是关于动态添加按钮的,需要编写者在windows应用程序中手动先添加静态的一个按钮(将其id属性设为btn)和一个文本框(id=txt_msg)。随后双击窗体form,于后台复制如下代码,F5运行。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
}
private int count = 0;//用于计数,添加了多少个按钮
public Form1()
{
InitializeComponent();
}
private void btn_addButtons_Click(object sender, EventArgs e)
{
//计数,计算目前是添加的几个按钮
count++;
//计算待添加按钮的位置
int localY = this.btn_addButtons.Height * count;
int localX = 10 * count;
Button toAddButton = new Button();
//设置待添加按钮的属性
toAddButton.Name = "Button " + count;
toAddButton.Text = "按钮 " + count + " ";
toAddButton.Location = new Point(localX, localY);
//设置添加按钮的事件
toAddButton.MouseEnter +=
new System.EventHandler(this.btn_MouseEnter);
toAddButton.MouseLeave +=
new System.EventHandler(this.btn_MouseLeave);
toAddButton.Click += new System.EventHandler(this.btn_Click);
//把控件添加到窗口中
this.Controls.Add(toAddButton);
}
private void btn_MouseEnter(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//设为鼠标的背景颜色
currentButton.BackColor = Color.White;
}
private void btn_MouseLeave(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//设为鼠标的背景颜色
currentButton.BackColor =
System.Windows.Forms.Control.DefaultBackColor;
}
private void btn_Click(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//显示单击了哪个按钮
txt_msg.Text = "你单击了" + currentButton.Text;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
}
private int count = 0;//用于计数,添加了多少个按钮
public Form1()
{
InitializeComponent();
}
private void btn_addButtons_Click(object sender, EventArgs e)
{
//计数,计算目前是添加的几个按钮
count++;
//计算待添加按钮的位置
int localY = this.btn_addButtons.Height * count;
int localX = 10 * count;
Button toAddButton = new Button();
//设置待添加按钮的属性
toAddButton.Name = "Button " + count;
toAddButton.Text = "按钮 " + count + " ";
toAddButton.Location = new Point(localX, localY);
//设置添加按钮的事件
toAddButton.MouseEnter +=
new System.EventHandler(this.btn_MouseEnter);
toAddButton.MouseLeave +=
new System.EventHandler(this.btn_MouseLeave);
toAddButton.Click += new System.EventHandler(this.btn_Click);
//把控件添加到窗口中
this.Controls.Add(toAddButton);
}
private void btn_MouseEnter(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//设为鼠标的背景颜色
currentButton.BackColor = Color.White;
}
private void btn_MouseLeave(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//设为鼠标的背景颜色
currentButton.BackColor =
System.Windows.Forms.Control.DefaultBackColor;
}
private void btn_Click(object sender, System.EventArgs e)
{
//unboxing
Button currentButton = (Button)sender;
//显示单击了哪个按钮
txt_msg.Text = "你单击了" + currentButton.Text;
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
思想是:先用实例化类的方法,实例化一个空间,在主控件添加就行了
比如在打开页面,或者窗体的时候,在panel上新建一个按钮,在Page_Load()或者FormLoad()中添加如下代码
Button Btn=new Button();
//配置下按钮的属性
panel.controls.add(Btn);
比如在打开页面,或者窗体的时候,在panel上新建一个按钮,在Page_Load()或者FormLoad()中添加如下代码
Button Btn=new Button();
//配置下按钮的属性
panel.controls.add(Btn);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询