• WinForm 小程序 NotePad


    运行效果:

    代码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 
    11 namespace FreeNotes
    12 {
    13     public partial class NotePad : Form
    14     {
    15         public NotePad()
    16         {
    17             InitializeComponent();
    18         }
    19 
    20         /// <summary>
    21         /// 打开文件事件
    22         /// </summary>
    23         private void btn_Open_Click(object sender, EventArgs e)
    24         {
    25             OpenFileDialog of = new OpenFileDialog();
    26 
    27             of.DefaultExt = "*.rtf";
    28 
    29             of.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*";
    30 
    31             if (of.ShowDialog() == DialogResult.OK && of.FileName.Length > 0)
    32             {
    33                 richTextBox1.LoadFile(of.FileName, RichTextBoxStreamType.RichText);
    34             }
    35         }
    36 
    37         /// <summary>
    38         /// 保存文件事件
    39         /// </summary>
    40         private void btn_Save_Click(object sender, EventArgs e)
    41         {
    42             SaveFileDialog sa = new SaveFileDialog();
    43 
    44             sa.Title = "保存";
    45 
    46             sa.FileName = "*.rtf";
    47 
    48             sa.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*";
    49 
    50             sa.DefaultExt = "*.rtf";
    51 
    52             if (sa.ShowDialog() == DialogResult.OK && sa.FileName.Length > 0)
    53             {
    54                 richTextBox1.SaveFile(sa.FileName, RichTextBoxStreamType.RichText);
    55             }
    56         }
    57 
    58         /// <summary>
    59         /// 字体事件
    60         /// </summary>
    61         private void btn_Font_Click(object sender, EventArgs e)
    62         {
    63             FontDialog fda = new FontDialog();
    64 
    65             fda.ShowColor = true;
    66 
    67             if (fda.ShowDialog() != DialogResult.Cancel)
    68             {
    69                 richTextBox1.SelectionFont = fda.Font;
    70                 richTextBox1.SelectionColor = fda.Color;
    71             }
    72         }
    73 
    74         /// <summary>
    75         /// 清空文本事件
    76         /// </summary>
    77         private void btn_Clear_Click(object sender, EventArgs e)
    78         {
    79             richTextBox1.Clear();
    80         }
    81     }
    82 }
  • 相关阅读:
    永续债的会计处理
    python基于粒子群优化的投资组合优化研究
    R语言使用Metropolis- Hasting抽样算法进行逻辑回归
    R语言使用K-Means聚类可视化WiFi访问
    R语言实现拟合神经网络预测和结果可视化
    Python Monte Carlo K-Means聚类实战研究
    R语言: GARCH模型股票交易量的研究道琼斯股票市场指数
    R语言stan泊松回归Poisson regression
    R语言旅行推销员问题TSP
    在R语言和Stan中估计截断泊松分布
  • 原文地址:https://www.cnblogs.com/KTblog/p/4394089.html
Copyright © 2020-2023  润新知