GrapeCity.Win.Editors.v80 アセンブリ > GrapeCity.Win.Editors 名前空間 > EditBase クラス : SelectionLength プロパティ |
Public Overridable Property SelectionLength As Integer
public virtual int SelectionLength {get; set;}
例外 | 解説 |
---|---|
System.ArgumentOutOfRangeException | 指定された値が0未満です。 |
SelectionStart 、 SelectionLength、SelectedTextの 各プロパティを.NET FrameworkのClipboardオブジェクトと 組み合わせて使うと、切り取り、コピー、貼り付けの各操作を実行できます。
Enter イベントの発生時に、ユーザーはフォーカスを受け取った コントロール上でSelectionStart プロパティとSelectionLength プロパティを設定し、カーソル位置と選択範囲を設定することができます。
// Please use the following namespace // using System.Windows.Forms; // using GrapeCity.Win.Editors; private GcTextBox gcTextBox1 = new GcTextBox(); private void Menu_Copy(System.Object sender, System.EventArgs e) { // Ensure that text is selected in the text box. if (gcTextBox1.SelectionLength > 0) // Copy the selected text to the Clipboard. gcTextBox1.Copy(); } private void Menu_Cut(System.Object sender, System.EventArgs e) { // Ensure that text is currently selected in the text box. if (gcTextBox1.SelectedText != "") // Cut the selected text in the control and paste it into the Clipboard. gcTextBox1.Cut(); } private void Menu_Paste(System.Object sender, System.EventArgs e) { // Determine if there is any text in the Clipboard to paste into the text box. if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true) { // Determine if any text is selected in the text box. if (gcTextBox1.SelectionLength > 0) { // Ask user if they want to paste over currently selected text. if (MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) == DialogResult.No) // Move selection to the point after the current selection and paste. gcTextBox1.SelectionStart = gcTextBox1.SelectionStart + gcTextBox1.SelectionLength; } // Paste current text in Clipboard into text box. gcTextBox1.Paste(); } } private void Menu_Undo(System.Object sender, System.EventArgs e) { // Determine if last operation can be undone in text box. if (gcTextBox1.CanUndo == true) { // Undo the last operation. gcTextBox1.Undo(); // Clear the undo buffer to prevent last action from being redone. gcTextBox1.ClearUndo(); } }
' Please use the following namespace ' Imports System.Windows.Forms; ' Imports GrapeCity.Win.Editors; Private gcTextBox1 As New GcTextBox() Private Sub Menu_Copy(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Ensure that text is selected in the text box. If gcTextBox1.SelectionLength > 0 Then ' Copy the selected text to the Clipboard. gcTextBox1.Copy() End If End Sub Private Sub Menu_Cut(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Ensure that text is currently selected in the text box. If gcTextBox1.SelectedText <> "" Then ' Cut the selected text in the control and paste it into the Clipboard. gcTextBox1.Cut() End If End Sub Private Sub Menu_Paste(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Determine if there is any text in the Clipboard to paste into the text box. If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then ' Determine if any text is selected in the text box. If gcTextBox1.SelectionLength > 0 Then ' Ask user if they want to paste over currently selected text. If MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) = DialogResult.No Then ' Move selection to the point after the current selection and paste. gcTextBox1.SelectionStart = gcTextBox1.SelectionStart + gcTextBox1.SelectionLength End If End If ' Paste current text in Clipboard into text box. gcTextBox1.Paste() End If End Sub Private Sub Menu_Undo(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Determine if last operation can be undone in text box. If gcTextBox1.CanUndo = True Then ' Undo the last operation. gcTextBox1.Undo() ' Clear the undo buffer to prevent last action from being redone. gcTextBox1.ClearUndo() End If End Sub