📄 notepadform.cs
字号:
//
// A basic Notepad application for Smartphone to demonstrate file handling dialogs
//
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
namespace OpenNETCF.Applications
{
/// <summary>
/// A basic text file viewer
/// </summary>
public class NotepadForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtContents;
private System.Windows.Forms.MenuItem mnuOpen;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuMenu;
private System.Windows.Forms.MenuItem mnuQuit;
//create an open file dialog
private OpenNETCF.Windows.Forms.OpenFileDialog ofd;
/// <summary>
/// </summary>
public NotepadForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
ofd = new OpenNETCF.Windows.Forms.OpenFileDialog();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
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.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mnuOpen = new System.Windows.Forms.MenuItem();
this.txtContents = new System.Windows.Forms.TextBox();
this.mnuMenu = new System.Windows.Forms.MenuItem();
this.mnuQuit = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.mnuOpen);
this.mainMenu1.MenuItems.Add(this.mnuMenu);
//
// mnuOpen
//
this.mnuOpen.Text = "Open";
this.mnuOpen.Click += new System.EventHandler(this.mnuOpen_Click);
//
// txtContents
//
this.txtContents.AcceptsReturn = true;
this.txtContents.AcceptsTab = true;
this.txtContents.Multiline = true;
this.txtContents.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtContents.Size = new System.Drawing.Size(176, 176);
this.txtContents.Text = "";
//
// mnuMenu
//
this.mnuMenu.MenuItems.Add(this.mnuQuit);
this.mnuMenu.Text = "Menu";
//
// mnuQuit
//
this.mnuQuit.Text = "Quit";
this.mnuQuit.Click += new System.EventHandler(this.mnuQuit_Click);
//
// NotepadForm
//
this.ControlBox = false;
this.Controls.Add(this.txtContents);
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.Text = "Notepad";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new NotepadForm());
}
private void mnuOpen_Click(object sender, System.EventArgs e)
{
ofd.Reset();
//set dialog to display only text files
ofd.Filter = "Text Files|*.txt;*.xml;*.htm";
ofd.FilterIndex = 1;
//show dialog to user
if(ofd.ShowDialog()==DialogResult.OK)
{
//open stream to file
StreamReader sr = File.OpenText(ofd.FileName);
//read entire file into textbox
txtContents.Text = sr.ReadToEnd();
//close streamreader
sr.Close();
}
}
private void mnuQuit_Click(object sender, System.EventArgs e)
{
//close application
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -