窗体(文本框,按钮,单选按钮,标签)

xiaoxiao2021-02-28  97

运行结果:

问题:

        //6.设计一个如图实验8-6所示的窗体。窗体上有两个文本框:一个文本框中最多输入字符6个;一个文本框中输入任何内容都显示*号。         //再添加一个按钮、两个单选按钮。实现单击按钮后,根据单选按钮,将对应文本框中内容显示在标签

代码:

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 实验8._6 { public partial class Form1 : Form { String s; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Text = "单选按钮实验"; radioButton1.Text="获取第一个文本框的内容"; radioButton2.Text = "获取第二个文本框的内容"; button1.Text = "根据单选按钮,将对应文本框中内容显示在标签"; } private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.MaxLength = 6; } private void textBox2_TextChanged(object sender, EventArgs e) { textBox2.PasswordChar ='*'; } private void radioButton1_CheckedChanged(object sender, EventArgs e) { s = textBox1.Text; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { s = textBox2.Text; } private void button1_Click(object sender, EventArgs e) { label1.Text = s; } } }

转载请注明原文地址: https://www.6miu.com/read-71847.html

最新回复(0)