標籤:
program.cs
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace NumChoose{ static class Program { /// <summary> /// 應用程式的主進入點。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); //DecimalPlaces 數字顯示框中要顯示的十進位數 //Hexadeccimal 指示數字是否以十六進位格式顯示所包括的的值 //Increment 向上或向下單擊button時,數字顯示框遞增或遞減的值 //InterceptArrowKeys 指示使用者能否夠使用向上或向下鍵選擇值 //Maximum 顯示框最大值 //Minumum 顯示框最小同意值 //Value NumericUpDown 空間中顯示的數值 //UpDownAlign 顯示框中向上或向下button的對齊 //DownButton 減小數字顯示框中的值 //UpButton 添加數字顯示框中的值 } }}
Form1.cs:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace NumChoose{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { numericUpDown1.Minimum = 1; //設定最小值1 numericUpDown1.Maximum = 20; //設定最大值20 numericUpDown1.DecimalPlaces = 2; //設定空間的DecimaPlaces屬性,使空間的數值小數點後兩位顯示 numericUpDown1.Increment = 1; //設定遞增或遞減 numericUpDown1.InterceptArrowKeys = true;//設定使用者能夠通過向上,向下鍵選擇值 } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { label2.Text = "選中的數值為: " + numericUpDown1.Value; } }}
Form1設計:
namespace NumChoose{ 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(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(102, 22); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(120, 21); this.numericUpDown1.TabIndex = 0; this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(37, 26); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(59, 12); this.label1.TabIndex = 1; this.label1.Text = "選擇數字:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(37, 62); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(0, 12); this.label2.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(305, 121); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.numericUpDown1); this.Name = "Form1"; this.Text = "數字選擇"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; }}
C#-numericUpDown-數字選擇---ShinePans