Advertisement
Shirai

Read and write Unicode code with richtextbox WindowForm

Apr 3rd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace RichTextBox
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             using (var dialog = new SaveFileDialog())
  24.             {
  25.                 if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName.Length > 0)
  26.                 {
  27.                     dialog.DefaultExt = "txt";
  28.                     dialog.Filter = "Text files (*.txt)|*.txt";
  29.                     richTextBox1.SaveFile(dialog.FileName, RichTextBoxStreamType.UnicodePlainText);
  30.                 }
  31.             }
  32.         }
  33.  
  34.         private void button2_Click(object sender, EventArgs e)
  35.         {
  36.             using (var dialog = new OpenFileDialog())
  37.             {
  38.                 if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName.Length > 0)
  39.                 {
  40.                     var text = File.ReadAllText(dialog.FileName, Encoding.Unicode);
  41.                     richTextBox1.Text = text;
  42.                 }
  43.             }
  44.            
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement