/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* Copyright (c) 2011, 煙臺大學計算機學院學生
* All rights reserved.
* 文件名稱:設計一個窗體
* 作 者: 雷恆鑫
* 完成日期: 2012 年 11 月 10 日
* 版 本 號: V1.0
* 對任務及求解方法的描述部分
* 輸入描述:窗體標題爲“我文本框實驗”;窗體上一個標籤,窗體上有一個文本框,文本框只能輸入0至9這十種數字.
* 輸入描述:且最多輸入8個數字;單擊結束按鈕程序即可結束。
* 問題描述:
* 程序輸出:
* 程序頭部的註釋結束
*/
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 WindowsFormsApplication_twelve
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
//this.FormBorderStyle = FormBorderStyle.FixedSingle;
}
private void button1_Click(object sender, EventArgs e)
{
// label1.Text = DateTime.Now.ToString();
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "我的文本框實驗";
/*button1.Text = "單擊該按鈕顯示系統當前時間";
this.MaximizeBox = false;
this.MinimizeBox = false;*/
this.StartPosition = FormStartPosition.CenterScreen;
button1.Text = "確定";
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
textBox1.MaxLength = 8;
if (e.KeyChar < '0' || e.KeyChar > '9')
{
e.Handled = false;
}
}
}
}
運行結果: