📄 frmstudententry.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
namespace Example_7
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmStudentEntry : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblFirstName;
private System.Windows.Forms.Label lblLastName;
private System.Windows.Forms.Label lblClass;
private System.Windows.Forms.Label lblGrade;
private System.Windows.Forms.TextBox txtFirstName;
private System.Windows.Forms.TextBox txtClass;
private System.Windows.Forms.TextBox txtGrade;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TextBox txtLastName;
private System.Windows.Forms.Button btnSave;
private FileStream fstream;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmStudentEntry()
{
InitializeComponent();
fstream = File.Create("C:\\Student.txt");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblFirstName = new System.Windows.Forms.Label();
this.lblLastName = new System.Windows.Forms.Label();
this.lblClass = new System.Windows.Forms.Label();
this.lblGrade = new System.Windows.Forms.Label();
this.txtFirstName = new System.Windows.Forms.TextBox();
this.txtClass = new System.Windows.Forms.TextBox();
this.txtGrade = new System.Windows.Forms.TextBox();
this.btnSave = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.txtLastName = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lblFirstName
//
this.lblFirstName.Location = new System.Drawing.Point(19, 17);
this.lblFirstName.Name = "lblFirstName";
this.lblFirstName.Size = new System.Drawing.Size(87, 25);
this.lblFirstName.TabIndex = 0;
this.lblFirstName.Text = "名字:";
//
// lblLastName
//
this.lblLastName.Location = new System.Drawing.Point(19, 52);
this.lblLastName.Name = "lblLastName";
this.lblLastName.Size = new System.Drawing.Size(77, 24);
this.lblLastName.TabIndex = 1;
this.lblLastName.Text = "姓氏:";
//
// lblClass
//
this.lblClass.Location = new System.Drawing.Point(19, 95);
this.lblClass.Name = "lblClass";
this.lblClass.Size = new System.Drawing.Size(77, 25);
this.lblClass.TabIndex = 2;
this.lblClass.Text = "班级:";
//
// lblGrade
//
this.lblGrade.Location = new System.Drawing.Point(19, 129);
this.lblGrade.Name = "lblGrade";
this.lblGrade.Size = new System.Drawing.Size(77, 25);
this.lblGrade.TabIndex = 3;
this.lblGrade.Text = "年级:";
//
// txtFirstName
//
this.txtFirstName.Location = new System.Drawing.Point(134, 17);
this.txtFirstName.Name = "txtFirstName";
this.txtFirstName.Size = new System.Drawing.Size(120, 21);
this.txtFirstName.TabIndex = 4;
this.txtFirstName.Text = "";
//
// txtClass
//
this.txtClass.Location = new System.Drawing.Point(134, 90);
this.txtClass.Name = "txtClass";
this.txtClass.Size = new System.Drawing.Size(120, 21);
this.txtClass.TabIndex = 6;
this.txtClass.Text = "";
//
// txtGrade
//
this.txtGrade.Location = new System.Drawing.Point(134, 127);
this.txtGrade.Name = "txtGrade";
this.txtGrade.Size = new System.Drawing.Size(120, 21);
this.txtGrade.TabIndex = 7;
this.txtGrade.Text = "";
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(32, 172);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(99, 25);
this.btnSave.TabIndex = 8;
this.btnSave.Text = "保存到文件(&S)";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(164, 172);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(90, 25);
this.btnExit.TabIndex = 9;
this.btnExit.Text = "退出(&E)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// txtLastName
//
this.txtLastName.Location = new System.Drawing.Point(134, 54);
this.txtLastName.Name = "txtLastName";
this.txtLastName.Size = new System.Drawing.Size(120, 21);
this.txtLastName.TabIndex = 5;
this.txtLastName.Text = "";
//
// frmStudentEntry
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(268, 203);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.txtGrade);
this.Controls.Add(this.txtClass);
this.Controls.Add(this.txtLastName);
this.Controls.Add(this.txtFirstName);
this.Controls.Add(this.lblGrade);
this.Controls.Add(this.lblClass);
this.Controls.Add(this.lblLastName);
this.Controls.Add(this.lblFirstName);
this.Name = "frmStudentEntry";
this.Text = "学生详细信息";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmStudentEntry());
}
private void btnSave_Click(object sender, System.EventArgs e)
{
//Prepare to write text to file
string data;
data = txtFirstName.Text + " " + txtLastName.Text + " " +txtClass.Text;
data += " " + txtGrade.Text +"\n";
Byte[] info = new
UTF8Encoding(true).GetBytes(data);
//Write the data
fstream.Write(info, 0, info.Length);
//Flush and close the FileStream
fstream.Flush();
fstream.Close();
frmStudentFile objfrmStudentFile = new frmStudentFile();
objfrmStudentFile.Show();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -