📄 form1.cs
字号:
namespace WinApp_Rwtext
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;
using System.IO;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.WinForms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.WinForms.ListBox listBox1;
private System.WinForms.Button button2;
private System.WinForms.Button button1;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.button1 = new System.WinForms.Button ();
this.button2 = new System.WinForms.Button ();
this.listBox1 = new System.WinForms.ListBox ();
//@this.TrayHeight = 0;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
button1.Location = new System.Drawing.Point (80, 40);
button1.Size = new System.Drawing.Size (80, 24);
button1.TabIndex = 0;
button1.Text = "写文本文件";
button1.Click += new System.EventHandler (this.button1_Click);
button2.Visible = true;
button2.Location = new System.Drawing.Point (232, 40);
button2.Size = new System.Drawing.Size (80, 24);
button2.TabIndex = 1;
button2.Text = "读文本文件";
button2.Click += new System.EventHandler (this.button2_Click);
listBox1.Location = new System.Drawing.Point (48, 120);
listBox1.Size = new System.Drawing.Size (312, 172);
listBox1.TabIndex = 2;
this.Text = "Form1";
this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
this.ClientSize = new System.Drawing.Size (416, 325);
this.Controls.Add (this.listBox1);
this.Controls.Add (this.button2);
this.Controls.Add (this.button1);
}
protected void button2_Click (object sender, System.EventArgs e)
{
File fl=new File("C:\\Writer.txt");
StreamReader strm=fl.OpenText();
string sLine;
do
{
sLine=strm.ReadLine();
AddItem(sLine);
} while (sLine!=null);
strm.Close();
}
private int iItems=0;
public void AddItem(string sItem)
{
listBox1.InsertItem(iItems,sItem);
++iItems;
}
protected void button1_Click (object sender, System.EventArgs e)
{
AddItem("Now are writting file data!");
StreamWriter strm=new StreamWriter("C:\\writer.txt",false);
strm.WriteLine("This is an example!");
strm.WriteLine("The following are kind of data");
strm.WriteLine("3333333333");
strm.WriteLine("4.5555555");
strm.WriteLine("and is following");
strm.WriteLine("true");
strm.WriteLine("false");
strm.WriteLine("This is an end");
strm.Close();
AddItem(" ");
AddItem("Completer!!!!");
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -