using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WinFormsApp16 { public class student { private int stuno; private string stuname; private int stuage; private string stusex; private string stuspeciality; public student(int myno ,string myname, int myage ,string mysex,string myspecility) { this.Stuno = myno; this.Stuname = myname; this.Stuage = myage; this.Stusex = mysex; this.Stuspeciality = myspecility; } public int Stuno { get => stuno; } public string Stuname { get => stuname; } public string Stusex { get => stusex; } public string Stuspeciality { get => stuspeciality; set => stuspeciality = value; } public int Stuage { get => stuage; set => stuage = value; } } }把这段代码优化成输入信息后再只读
时间: 2024-02-14 19:04:37 浏览: 140
这段代码是 C# 语言的代码,可以通过在 Windows 系统上安装 Visual Studio 编辑器进行修改和运行。
以下是将该代码优化为输入信息后再只读的代码示例:
```csharp
using System;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class Form1 : Form
{
private int stuno;
private string stuname;
private int stuage;
private string stusex;
private string stuspeciality;
public Form1()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
stuno = int.Parse(txtStuno.Text);
stuname = txtStuname.Text;
stuage = int.Parse(txtStuage.Text);
stusex = txtStusex.Text;
stuspeciality = txtStuspeciality.Text;
// 显示信息
txtInfo.Text = $"学号:{stuno}\r\n姓名:{stuname}\r\n年龄:{stuage}\r\n性别:{stusex}\r\n专业:{stuspeciality}";
// 设置文本框只读
txtStuno.ReadOnly = true;
txtStuname.ReadOnly = true;
txtStuage.ReadOnly = true;
txtStusex.ReadOnly = true;
txtStuspeciality.ReadOnly = true;
}
}
}
```
这段代码实现了一个简单的 Windows 窗体应用程序,包含了一个输入学生信息的表单,用户在填写完信息后,点击提交按钮,会将学生信息显示在一个文本框中,并将输入框设置为只读状态,不允许再次编辑。
阅读全文