/// <summary> /// Initializes a new instance of the Selection class by associating it with a TextBox derived object. /// and then selecting text on it. </summary> /// <param name="textBox"> /// The TextBox object for which the selection is being manipulated. </param> /// <param name="start"> /// The zero-based position where to start the selection. </param> /// <param name="end"> /// The zero-based position where to end the selection. If it's equal to the start position, no text is selected. </param> /// <seealso cref="System.Windows.Forms.TextBox" /> public Selection(TextBox textBox, int start, int end) { this.textBox = textBox; Set(start, end); }
/// <summary> /// Disables restoring of the textbox's selection when <see cref="Dispose" /> is called. </summary> /// <seealso cref="Dispose" /> /// <seealso cref="Update" /> public void Disable() { textBox = null; }
/// <summary> /// Initializes a new instance of the Selection class by associating it with a TextBox derived object. </summary> /// <param name="textBox"> /// The TextBox object for which the selection is being manipulated. </param> /// <seealso cref="System.Windows.Forms.TextBox" /> public Selection(TextBox textBox) { this.textBox = textBox; }
/// <summary> /// Restores the selection on the textbox to the saved start and end values. </summary> /// <remarks> /// This method checks that the textbox is still <see cref="Disable">available</see> /// and if so restores the selection. </remarks> /// <seealso cref="Disable" /> public void Restore() { if (textBox == null) return; selection.Set(this.start, this.end); textBox = null; }
/// <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); }