/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* Copyright (c) 2011, 煙臺大學計算機學院學生
* All rights reserved.
* 文件名稱:設計一個窗體
* 作 者: 雷恆鑫
* 完成日期: 2012 年 11 月 10 日
* 版 本 號: V1.0
* 對任務及求解方法的描述部分
* 輸入描述:窗體上有兩個文本框:一個文本框中最多輸入字符6個;
* 輸入描述:一個文本框中輸入任何內容都顯示*號。
* 輸入描述:再添加一個按鈕、2個單選按鈕。實現單擊按鈕後。
* 輸入描述:根據單選按鈕,將對應文本框中內容顯示在標籤。
* 問題描述:
* 程序輸出:
* 程序頭部的註釋結束
*/
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
{
Boolean b = true;
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
//this.FormBorderStyle = FormBorderStyle.FixedSingle;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// label1.Text = DateTime.Now.ToString();
if (b == false)
{
textBox1.SelectAll();
label1.Text = textBox1.SelectedText;
}
else
{
textBox2.SelectAll();
label1.Text = textBox2.SelectedText;
}
}
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 textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
textBox1.MaxLength = 6;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
textBox2.PasswordChar = '*';
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
b = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
b = true;
}
}
}
運行結果;