这篇文章主要介绍“C#控件属性和InitializeComponent()的关系”,在日常操作中,相信很多人在C#控件属性和InitializeComponent()的关系问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”C#控件属性和InitializeComponent()的关系”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
namespace Test22
{
partial class Form1
{
/// <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.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// numericUpDown1
//
this.numericUpDown1.DecimalPlaces = 4;//属性里对应!!!!!
this.numericUpDown1.Location = new System.Drawing.Point(12, 12);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(120, 21);
this.numericUpDown1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(153, 53);
this.Controls.Add(this.numericUpDown1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.NumericUpDown numericUpDown1;
}
}
控件中小数点位数和InitializeComponent()里面的代码相呼应,而下面的代码又设置了2,所以覆盖掉了,代码和运行结果如下:
using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown1.Maximum = 20;
numericUpDown1.Minimum = 1;
numericUpDown1.DecimalPlaces = 2;
}
}
}
到此,关于“C#控件属性和InitializeComponent()的关系”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。