次の方法で共有


UpDownBase.Select メソッド

アップダウン コントロールのテキストの範囲を選択します。

オーバーロードの一覧

選択する対象の文字の開始位置と文字数を指定する、アップダウン コントロールのテキストの範囲を選択します。

[Visual Basic] Overloads Public Sub Select(Integer, Integer)

[C#] public void Select(int, int);

[C++] public: void Select(int, int);

[JScript] public function Select(int, int);

Control から継承されます。

[Visual Basic] Overloads Public Sub Select()

[C#] public void Select();

[C++] public: void Select();

[JScript] public function Select();

Control から継承されます。

[Visual Basic] Overloads Protected Overridable Sub Select(Boolean, Boolean)

[C#] protected virtual void Select(bool, bool);

[C++] protected: virtual void Select(bool, bool);

[JScript] protected function Select(Boolean, Boolean);

使用例

[Visual Basic, C#, C++] 派生クラス NumericUpDown を使用する例を次に示します。このコードは、 NumericUpDown コントロールと Button がフォーム上に作成されていること、および System.Drawing 名前空間が参照として追加されていることを前提にしています。ボタンの Click が発生すると、 NumericUpDown コントロールのテキストのポイント数が増えます。ポイント数が増えると、コントロールにすべてのテキストを表示できるように、コントロールで PreferredHeight プロパティを調整するように促されます。ユーザーが新しい値を入力して NumericUpDown コントロールを終了すると、テキストが文字列値から数値へ変換され、 Minimum 値と Maximum 値の間にあるかどうかが検証されます。値が無効な場合は、 MessageBox にエラーが表示され、ユーザーが新しい値を入力できるように Select メソッドがテキストを選択します。

[Visual Basic, C#, C++] メモ   ここでは、Select のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Private Sub numericUpDown1_Leave(sender As Object, e As EventArgs)
    ' If the entered value is greater than Minimum or Maximum,
    ' select the text and open a message box. 
    If (System.Convert.ToInt32(numericUpDown1.Text) > numericUpDown1.Maximum) Or _
        (System.Convert.ToInt32(numericUpDown1.Text) < numericUpDown1.Minimum) Then
        MessageBox.Show("The value entered was not between the Minimum and " & _
            "Maximum allowable values." & Microsoft.VisualBasic.ControlChars.Cr & _
            "Please re-enter.")
        numericUpDown1.Focus()
        numericUpDown1.Select(0, numericUpDown1.Text.Length)
    End If
End Sub    

Private Sub button1_Click(sender As Object, e As EventArgs)
    Dim varPrefHeight1 As Integer
    
    ' Capture the PreferredHeight before and after the Font
    ' is changed, and display the results in a message box. 
    varPrefHeight1 = numericUpDown1.PreferredHeight
    numericUpDown1.Font = New System.Drawing.Font("Microsoft Sans Serif", _
        12F, System.Drawing.FontStyle.Bold)
    MessageBox.Show("Before Font Change: " & varPrefHeight1.ToString() & _
        Microsoft.VisualBasic.ControlChars.Cr & "After Font Change: " & _
        numericUpDown1.PreferredHeight.ToString())
End Sub


[C#] 
private void numericUpDown1_Leave(Object sender,
                                  EventArgs e)
{
   /* If the entered value is greater than Minimum or Maximum,
      select the text and open a message box. */
   if((System.Convert.ToInt32(numericUpDown1.Text) > numericUpDown1.Maximum) ||
      (System.Convert.ToInt32(numericUpDown1.Text) < numericUpDown1.Minimum))
   {
      MessageBox.Show("The value entered was not between the Minimum and" +
         "Maximum allowable values." + "\n" + "Please re-enter.");
      numericUpDown1.Focus();
      numericUpDown1.Select(0, numericUpDown1.Text.Length);
   }
}
   
private void button1_Click(Object sender,
                           EventArgs e)
{
   int varPrefHeight1;
   
   /* Capture the PreferredHeight before and after the Font
      is changed, and display the results in a message box. */
   varPrefHeight1 = numericUpDown1.PreferredHeight;
   numericUpDown1.Font = new System.Drawing.Font("Microsoft Sans Serif",
      12F, System.Drawing.FontStyle.Bold);
   MessageBox.Show("Before Font Change: " + varPrefHeight1.ToString() +
      "\n" + "After Font Change: " + numericUpDown1.PreferredHeight.ToString());
}


[C++] 
private:
void numericUpDown1_Leave(Object* /*sender*/,
                          EventArgs* /*e*/)
{
   /* If the entered value is greater than Minimum or Maximum,
      select the text and open a message box. */
   if((System::Convert::ToInt32(numericUpDown1->Text) > numericUpDown1->Maximum) ||
      (System::Convert::ToInt32(numericUpDown1->Text) < numericUpDown1->Minimum))
   {
      MessageBox::Show(S"The value entered was not between the Minimum andMaximum allowable values.\nPlease re-enter.");
      numericUpDown1->Focus();
      numericUpDown1->Select(0, numericUpDown1->Text->Length);
   }
}
   
void button1_Click(Object* /*sender*/,
                   EventArgs* /*e*/)
{
   int varPrefHeight1;
   
   /* Capture the PreferredHeight before and after the Font
      is changed, and display the results in a message box. */
   varPrefHeight1 = numericUpDown1->PreferredHeight;
   numericUpDown1->Font = new System::Drawing::Font(S"Microsoft Sans Serif",
      12.0, System::Drawing::FontStyle::Bold);
   MessageBox::Show(String::Format( S"Before Font Change: {0}\nAfter Font Change: {1}",
      __box(varPrefHeight1), __box(numericUpDown1->PreferredHeight)));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

UpDownBase クラス | UpDownBase メンバ | System.Windows.Forms 名前空間