C# 控件屬性和InitializeComponent()關(guān)系案例詳解
namespace Test22 { partial class Form1 { /// <summary> /// 必需的設(shè)計(jì)器變量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的資源。 /// </summary> /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設(shè)計(jì)器生成的代碼 /// <summary> /// 設(shè)計(jì)器支持所需的方法 - 不要 /// 使用代碼編輯器修改此方法的內(nèi)容。 /// </summary> private void InitializeComponent() { this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // numericUpDown1 // this.numericUpDown1.DecimalPlaces = 4;//屬性里對應(yīng)!?。。。? 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; } }
控件中小數(shù)點(diǎn)位數(shù)和InitializeComponent()里面的代碼相呼應(yīng),而下面的代碼又設(shè)置了2,所以覆蓋掉了,代碼和運(yùn)行結(jié)果如下:
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; } } }
到此這篇關(guān)于C# 控件屬性和InitializeComponent()關(guān)系案例詳解的文章就介紹到這了,更多相關(guān)C# 控件屬性和InitializeComponent()關(guān)系內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#使用百度Ueditor富文本框?qū)崿F(xiàn)上傳文件
這篇文章主要為大家詳細(xì)介紹了C#如何使用百度Ueditor富文本框?qū)崿F(xiàn)上傳文件(圖片,視頻等),文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-07-07C#導(dǎo)出生成excel文件的方法小結(jié)(xml,html方式)
C#導(dǎo)出生成excel文件的方法小結(jié)(xml,html方式)。需要的朋友可以過來參考下,希望對大家有所幫助2013-10-10C#簡單實(shí)現(xiàn)在網(wǎng)頁上發(fā)郵件的案例
本文分享一個(gè)C#利用SMTP發(fā)送郵件的案例,提供了前后臺(tái)代碼,方便大家學(xué)習(xí)。2016-03-03c#打印預(yù)覽控件中實(shí)現(xiàn)用鼠標(biāo)移動(dòng)頁面功能代碼分享
項(xiàng)目中需要實(shí)現(xiàn)以下功能:打印預(yù)覽控件中,可以用鼠標(biāo)拖動(dòng)頁面,以查看超出顯示范圍之外的部分內(nèi)容,下面就是實(shí)現(xiàn)代碼2013-12-12C#中遍歷DataSet數(shù)據(jù)集對象實(shí)例
這篇文章主要介紹了C#中遍歷DataSet數(shù)據(jù)集對象實(shí)例,經(jīng)常忘記如何操作DataSet,這里記下來并分享,讓需要的朋友可以參考下2014-08-08C#使用自定義的泛型節(jié)點(diǎn)類實(shí)現(xiàn)二叉樹類
這篇文章主要為大家詳細(xì)介紹了C#如何使用自定義的泛型節(jié)點(diǎn)類 Node<T>實(shí)現(xiàn)二叉樹類BinaryTree<T>及其方法,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03C#實(shí)現(xiàn)六大設(shè)計(jì)原則之單一職責(zé)原則
這篇文章介紹了C#實(shí)現(xiàn)六大設(shè)計(jì)原則之單一職責(zé)原則的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02