C#--第11周實驗--任務1(建立Windows窗體應用程序)--設計一個窗體--單擊按鈕時,在標籤上顯示當前系統時間

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;

        }
    }
}


 

運行結果:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章