RichTextBoxControl.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Windows.Forms;
  3. using System.ComponentModel;
  4. using System.IO;
  5. using FastReport.Utils;
  6. using System.Runtime.InteropServices;
  7. namespace FastReport.Dialog
  8. {
  9. /// <summary>
  10. /// Represents a Windows rich text box control.
  11. /// Wraps the <see cref="System.Windows.Forms.RichTextBox"/> control.
  12. /// </summary>
  13. public class RichTextBoxControl : DialogControl
  14. {
  15. private RichTextBox5 richTextBox;
  16. #region Properties
  17. /// <summary>
  18. /// Gets an internal <b>RichTextBox</b>.
  19. /// </summary>
  20. [Browsable(false)]
  21. public RichTextBox RichTextBox
  22. {
  23. get { return richTextBox; }
  24. }
  25. /// <summary>
  26. /// Gets or sets the text of the RichTextBox control, including all rich text format (RTF) codes.
  27. /// Wraps the <see cref="System.Windows.Forms.RichTextBox.Rtf"/> property.
  28. /// </summary>
  29. [Category("Appearance")]
  30. public string Rtf
  31. {
  32. get { return RichTextBox.Rtf; }
  33. set { RichTextBox.Rtf = value; }
  34. }
  35. /// <summary>
  36. /// Gets or sets the type of scroll bars to display in the RichTextBox control.
  37. /// Wraps the <see cref="System.Windows.Forms.RichTextBox.ScrollBars"/> property.
  38. /// </summary>
  39. [DefaultValue(RichTextBoxScrollBars.Both)]
  40. [Category("Appearance")]
  41. public RichTextBoxScrollBars ScrollBars
  42. {
  43. get { return RichTextBox.ScrollBars; }
  44. set { RichTextBox.ScrollBars = value; }
  45. }
  46. #endregion
  47. #region Public Methods
  48. /// <inheritdoc/>
  49. public override void Serialize(FRWriter writer)
  50. {
  51. RichTextBoxControl c = writer.DiffObject as RichTextBoxControl;
  52. base.Serialize(writer);
  53. if (Rtf != c.Rtf)
  54. writer.WriteStr("Rtf", Rtf);
  55. if (ScrollBars != c.ScrollBars)
  56. writer.WriteValue("ScrollBars", ScrollBars);
  57. }
  58. /// <summary>
  59. /// Loads rtf from a file.
  60. /// </summary>
  61. /// <param name="path">File to load from.</param>
  62. public void LoadFile(string path)
  63. {
  64. RichTextBox.LoadFile(path);
  65. }
  66. /// <summary>
  67. /// Loads rtf from a stream using specified stream type.
  68. /// </summary>
  69. /// <param name="data">Stream to load from.</param>
  70. /// <param name="fileType">Type of a stream.</param>
  71. public void LoadFile(Stream data, RichTextBoxStreamType fileType)
  72. {
  73. RichTextBox.LoadFile(data, fileType);
  74. }
  75. /// <summary>
  76. /// Loads rtf from a file using specified stream type.
  77. /// </summary>
  78. /// <param name="path">File to load from.</param>
  79. /// <param name="fileType">Type of a stream.</param>
  80. public void LoadFile(string path, RichTextBoxStreamType fileType)
  81. {
  82. RichTextBox.LoadFile(path, fileType);
  83. }
  84. #endregion
  85. /// <summary>
  86. /// Initializes a new instance of the <b>RichTextBoxControl</b> class with default settings.
  87. /// </summary>
  88. public RichTextBoxControl()
  89. {
  90. richTextBox = new RichTextBox5();
  91. Control = richTextBox;
  92. }
  93. internal class RichTextBox5 : RichTextBox
  94. {
  95. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  96. static extern IntPtr LoadLibrary(string lpFileName);
  97. protected override CreateParams CreateParams
  98. {
  99. get
  100. {
  101. CreateParams cparams = base.CreateParams;
  102. if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
  103. {
  104. cparams.ClassName = "RICHEDIT50W";
  105. }
  106. return cparams;
  107. }
  108. }
  109. }
  110. }
  111. }