C# 控件屬性和InitializeComponent()關(guān)系案例詳解
更新時間:2021年08月27日 16:46:30 作者:劉要直
這篇文章主要介紹了C# 控件屬性和InitializeComponent()關(guān)系案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
namespace Test22
{
partial class Form1
{
/// <summary>
/// 必需的設(shè)計器變量。
/// </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è)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(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ù)點位數(shù)和InitializeComponent()里面的代碼相呼應(yīng),而下面的代碼又設(shè)置了2,所以覆蓋掉了,代碼和運行結(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)文章
用Newtonsoft將json串轉(zhuǎn)為對象的方法(詳解)
下面小編就為大家?guī)硪黄肗ewtonsoft將json串轉(zhuǎn)為對象的方法(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04
C#使用MVC框架創(chuàng)建WebApi服務(wù)接口的流程步驟
WebAPI是一種基于HTTP協(xié)議的網(wǎng)絡(luò)應(yīng)用程序接口,它使用JSON或XML格式來傳輸數(shù)據(jù),本文通過圖文和代碼示例給大家介紹了C#使用MVC框架創(chuàng)建WebApi服務(wù)接口的流程步驟,需要的朋友可以參考下2025-01-01

