using System; using System.Windows.Forms; using System.ComponentModel; using System.IO; using FastReport.Utils; using System.Runtime.InteropServices; namespace FastReport.Dialog { /// /// Represents a Windows rich text box control. /// Wraps the control. /// public class RichTextBoxControl : DialogControl { private RichTextBox5 richTextBox; #region Properties /// /// Gets an internal RichTextBox. /// [Browsable(false)] public RichTextBox RichTextBox { get { return richTextBox; } } /// /// Gets or sets the text of the RichTextBox control, including all rich text format (RTF) codes. /// Wraps the property. /// [Category("Appearance")] public string Rtf { get { return RichTextBox.Rtf; } set { RichTextBox.Rtf = value; } } /// /// Gets or sets the type of scroll bars to display in the RichTextBox control. /// Wraps the property. /// [DefaultValue(RichTextBoxScrollBars.Both)] [Category("Appearance")] public RichTextBoxScrollBars ScrollBars { get { return RichTextBox.ScrollBars; } set { RichTextBox.ScrollBars = value; } } #endregion #region Public Methods /// public override void Serialize(FRWriter writer) { RichTextBoxControl c = writer.DiffObject as RichTextBoxControl; base.Serialize(writer); if (Rtf != c.Rtf) writer.WriteStr("Rtf", Rtf); if (ScrollBars != c.ScrollBars) writer.WriteValue("ScrollBars", ScrollBars); } /// /// Loads rtf from a file. /// /// File to load from. public void LoadFile(string path) { RichTextBox.LoadFile(path); } /// /// Loads rtf from a stream using specified stream type. /// /// Stream to load from. /// Type of a stream. public void LoadFile(Stream data, RichTextBoxStreamType fileType) { RichTextBox.LoadFile(data, fileType); } /// /// Loads rtf from a file using specified stream type. /// /// File to load from. /// Type of a stream. public void LoadFile(string path, RichTextBoxStreamType fileType) { RichTextBox.LoadFile(path, fileType); } #endregion /// /// Initializes a new instance of the RichTextBoxControl class with default settings. /// public RichTextBoxControl() { richTextBox = new RichTextBox5(); Control = richTextBox; } internal class RichTextBox5 : RichTextBox { [DllImport("kernel32.dll", CharSet = CharSet.Auto)] static extern IntPtr LoadLibrary(string lpFileName); protected override CreateParams CreateParams { get { CreateParams cparams = base.CreateParams; if (LoadLibrary("msftedit.dll") != IntPtr.Zero) { cparams.ClassName = "RICHEDIT50W"; } return cparams; } } } } }