toolstripform.cs

来自「csharp课本的源代码」· CS 代码 · 共 72 行

CS
72
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ToolStripExample
{
    public partial class ToolStripForm : Form
    {
        public ToolStripForm()
        {
            InitializeComponent();
        }

        private void toolStripButton新建N_Click(object sender, EventArgs e)
        {
            richTextBox1.Enabled = true;
            richTextBox1.Clear();
            richTextBox1.Focus();

        }

        private void toolStripButton打开O_Click(object sender, EventArgs e)
        {
            richTextBox1.LoadFile("D:\\source.rtf", RichTextBoxStreamType.RichText);
            richTextBox1.Enabled = true;
        }
        private void toolStripButton保存S_Click(object sender, EventArgs e)
        {
            richTextBox1.SaveFile("D:\\source.rtf", RichTextBoxStreamType.RichText);
            richTextBox1.Clear();
            MessageBox.Show("source.rtf文件已保存!");
            richTextBox1.Enabled = false;
        }

        private void toolStripButton剪切U_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();
        }

        private void toolStripButton复制C_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();
        }

        private void toolStripButton粘贴P_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();
        }

        private void toolStripComboBox字体_TextChanged(object sender, EventArgs e)
        {
            FontFamily myfontfamily = richTextBox1.SelectionFont.FontFamily;
            switch (toolStripComboBox字体.Text)
            {
                case "大字体":
                    richTextBox1.Font = new Font(myfontfamily, 40, System.Drawing.FontStyle.Regular);
                    break;
                case "小字体":
                    richTextBox1.Font = new Font(myfontfamily, 8, System.Drawing.FontStyle.Regular);
                    break;
                case "适中字体":
                    richTextBox1.Font = new Font(myfontfamily, 24, System.Drawing.FontStyle.Regular);
                    break;
            }

        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?