C#--第11周實驗--任務1(建立Windows窗體應用程式)--設計一個窗體--單擊按鈕時,在標籤上顯示當前系統時間
阿新 • • 發佈:2019-02-08
Form.cs
/* (程式頭部註釋開始) * 程式的版權和版本宣告部分 * Copyright (c) 2011, 煙臺大學計算機學院學生 * All rights reserved. * 檔名稱:設計一個窗體 * 作 者: 雷恆鑫 * 完成日期: 2012 年 11 月 04 日 * 版 本 號: V1.0 * 對任務及求解方法的描述部分 * 輸入描述:該窗體自動位於螢幕中央;大小不可調;最小化、最大化按鈕不可用;窗體標題為“煙臺大學”。 * 輸入描述:在該窗體上,放置一個按鈕、一個標籤。單擊按鈕時,在標籤上顯示當前系統時間。 * 問題描述: * 程式輸出: * 程式頭部的註釋結束 */ 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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; } private void Form1_Load(object sender, EventArgs e) { this.Text = "煙臺大學"; //this.StartPosition = FormStartPosition; this.MaximizeBox = false; this.MinimizeBox = false; //this.StartPosition = FormStartPosition(); //this.StartPosition = FormStartPosition.CenterScreen; } private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { // button1.Text = "單擊該按鈕顯示系統當前時間"; label1.Text = DateTime.Now.ToString(); //MessageBox.Show(DateTime.Now.ToString()); } } }
執行結果:
改進後的程式:
改進後增加的功能:視窗大小不可調。
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(); } private void Form1_Load(object sender, EventArgs e) { this.Text = "煙臺大學"; button1.Text = "單擊該按鈕顯示系統當前時間"; this.MaximizeBox = false; this.MinimizeBox = false; this.StartPosition = FormStartPosition.CenterScreen; } } }
執行結果: