次の方法で共有


SelectionRange コンストラクタ (DateTime, DateTime)

指定した開始日および終了日を使用して、SelectionRange クラスの新しいインスタンスを初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

構文

'宣言
Public Sub New ( _
    lower As DateTime, _
    upper As DateTime _
)
'使用
Dim lower As DateTime
Dim upper As DateTime

Dim instance As New SelectionRange(lower, upper)
public SelectionRange (
    DateTime lower,
    DateTime upper
)
public:
SelectionRange (
    DateTime lower, 
    DateTime upper
)
public SelectionRange (
    DateTime lower, 
    DateTime upper
)
public function SelectionRange (
    lower : DateTime, 
    upper : DateTime
)

パラメータ

  • upper
    SelectionRange の終了日。

解説

注意

lower DateTime 値が upperDateTime 値より大きいと、lower 値が Start プロパティではなく End プロパティに代入されます。

使用例

Button がクリックされたときに、2 つの TextBox コントロールに入力された 2 つの日付に基づいて、MonthCalendar コントロールの SelectionRange プロパティを設定する例を次に示します。このコードは、MonthCalendar コントロールの新しいインスタンス、2 つの TextBox コントロール、および ButtonForm 上に作成されていることを前提にしています。テキスト ボックスに入力された Text を検証するためのコードを追加し、入力された日付が有効かどうかを確認できます。

Private Sub button1_Click(sender As Object, e As EventArgs)
   ' Set the SelectionRange with start and end dates from text boxes.
   Try
      monthCalendar1.SelectionRange = New SelectionRange( _
        DateTime.Parse(textBox1.Text), _
        DateTime.Parse(textBox2.Text))
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   End Try
End Sub
private void button1_Click(object sender,
                           EventArgs e)
{
   // Set the SelectionRange with start and end dates from text boxes.
   try
   {
      monthCalendar1.SelectionRange = new SelectionRange(
        DateTime.Parse(textBox1.Text),
        DateTime.Parse(textBox2.Text));
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}
private:
   void button1_Click( Object^ sender, EventArgs^ e )
   {
      // Set the SelectionRange with start and end dates from text boxes.
      try
      {
         monthCalendar1->SelectionRange = gcnew SelectionRange(
            DateTime::Parse( textBox1->Text ),
            DateTime::Parse( textBox2->Text ) );
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
private void button1_Click(Object sender, EventArgs e)
{
    // Set the SelectionRange with start and end dates from text boxes.
    try {
        monthCalendar1.set_SelectionRange(
        new SelectionRange(DateTime.Parse(textBox1.get_Text()), 
            DateTime.Parse(textBox2.get_Text())));
    }
    catch (System.Exception ex) {
        MessageBox.Show(ex.get_Message());
    }
} //button1_Click

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0

参照

関連項目

SelectionRange クラス
SelectionRange メンバ
System.Windows.Forms 名前空間
Start
End