/// <summary> /// Initializes a new instance of the Behavior class by associating it with a TextBox derived object. </summary> /// <param name="textBox"> /// The TextBox object to associate with this behavior. It must not be null. </param> /// <param name="addEventHandlers"> /// If true, the textBox's event handlers are tied to the corresponding methods on this behavior object. </param> /// <exception cref="ArgumentNullException">textBox is null. </exception> /// <remarks> /// This constructor is <c>protected</c> since this class is only meant to be used as a base for other behaviors. </remarks> /// <seealso cref="System.Windows.Forms.TextBox" /> /// <seealso cref="AddEventHandlers" /> protected Behavior(TextBox textBox, bool addEventHandlers) { if (textBox == null) throw new ArgumentNullException("textBox"); this.textBox = textBox; this.selection = new Selection(this.textBox); this.selection.TextChanging += new EventHandler(HandleTextChangingBySelection); if (addEventHandlers) AddEventHandlers(); }
/// <summary> /// Initializes a new instance of the Saver class by associating it with a TextBox derived object /// and passing the start and end position of the selection. </summary> /// <param name="textBox"> /// The TextBox object for which the selection is being saved. </param> /// <param name="start"> /// The zero-based start position of the selection. </param> /// <param name="end"> /// The zero-based end position of the selection. It must not be less than the start position. </param> /// <remarks> /// This constructor does not save the textbox's start and end position of the selection. /// Instead, it saves the two given parameters. </remarks> /// <seealso cref="System.Windows.Forms.TextBox" /> public Saver(TextBox textBox, int start, int end) { this.textBox = textBox; selection = new Selection(textBox); System.Diagnostics.Debug.Assert(start <= end); this.start = start; this.end = end; }
/// <summary> /// Initializes a new instance of the Saver class by associating it with a TextBox derived object. </summary> /// <param name="textBox"> /// The TextBox object for which the selection is being saved. </param> /// <remarks> /// This constructor saves the textbox's start and end position of the selection inside private fields. </remarks> /// <seealso cref="System.Windows.Forms.TextBox" /> public Saver(TextBox textBox) { this.textBox = textBox; selection = new Selection(textBox); selection.Get(out this.start, out this.end); }