RichSelectorForm.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.Text;
  8. using System.Windows.Forms;
  9. namespace FastReport.Forms
  10. {
  11. public partial class RichSelectorForm : BaseForm
  12. {
  13. RichObject rich_object;
  14. bool modified;
  15. /// <summary>
  16. /// Check if rich text was updated
  17. /// </summary>
  18. public bool IsModified { get { return modified; } }
  19. /// <summary>
  20. /// Load and save rich text
  21. /// </summary>
  22. /// <param name="obj"></param>
  23. public RichSelectorForm(RichObject obj)
  24. {
  25. rich_object = obj;
  26. InitializeComponent();
  27. modified = false;
  28. }
  29. private void button1_Click(object sender, EventArgs e)
  30. {
  31. OpenFileDialog dialog = new OpenFileDialog();
  32. dialog.Filter = "RichText files (*.rtf)|*.rtf";
  33. dialog.Title = "Load rich text";
  34. if (dialog.ShowDialog() == DialogResult.OK)
  35. {
  36. FileStream fs = new FileStream(dialog.FileName, FileMode.Open);
  37. byte[] text = new byte[fs.Length];
  38. fs.Read(text, 0, (int)fs.Length);
  39. rich_object.Text = System.Text.Encoding.Default.GetString(text);
  40. modified = true;
  41. }
  42. dialog.Dispose();
  43. this.Close();
  44. }
  45. private void button2_Click(object sender, EventArgs e)
  46. {
  47. SaveFileDialog dialog = new SaveFileDialog();
  48. dialog.Filter = "RichText files (*.rtf)|*.rtf";
  49. dialog.Title = "Save rich text to file...";
  50. if (dialog.ShowDialog() == DialogResult.OK)
  51. {
  52. byte[] text = System.Text.Encoding.UTF8.GetBytes(rich_object.Text);
  53. FileStream fs = new FileStream(dialog.FileName, FileMode.Create);
  54. fs.Write(text, 0, text.Length);
  55. fs.Close();
  56. }
  57. dialog.Dispose();
  58. this.Close();
  59. }
  60. }
  61. }