DomainUpDown.Items 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指派給微調方塊 (也稱為上下按鈕控制項) 的物件集合。
public:
property System::Windows::Forms::DomainUpDown::DomainUpDownItemCollection ^ Items { System::Windows::Forms::DomainUpDown::DomainUpDownItemCollection ^ get(); };
public System.Windows.Forms.DomainUpDown.DomainUpDownItemCollection Items { get; }
member this.Items : System.Windows.Forms.DomainUpDown.DomainUpDownItemCollection
Public ReadOnly Property Items As DomainUpDown.DomainUpDownItemCollection
屬性值
DomainUpDown.DomainUpDownItemCollection,包含 Object 集合。
範例
下列程式碼範例會建立並初始化 DomainUpDown 控制項。 此範例可讓您設定部分屬性,並建立字串集合以顯示在微調方塊中。 程式碼假設 TextBox CheckBox 、 和 Button 已在表單上具現化。 此範例也假設您在類別層級宣告為名為 myCounter
的 32 位帶正負號整數的成員變數。 您可以在文字方塊中輸入字串,並在按一下按鈕時將其新增至 Items 集合。 按一下核取方塊,您可以切換 屬性, Sorted 並觀察微調方塊中專案集合的差異。
protected:
DomainUpDown^ domainUpDown1;
private:
void MySub()
{
// Create and initialize the DomainUpDown control.
domainUpDown1 = gcnew System::Windows::Forms::DomainUpDown;
// Add the DomainUpDown control to the form.
Controls->Add( domainUpDown1 );
}
void button1_Click( System::Object^ sender,
System::EventArgs^ e )
{
// Add the text box contents and initial location in the collection
// to the DomainUpDown control.
domainUpDown1->Items->Add( String::Concat(
(textBox1->Text->Trim()), " - ", myCounter.ToString() ) );
// Increment the counter variable.
myCounter = myCounter + 1;
// Clear the TextBox.
textBox1->Text = "";
}
void checkBox1_Click( Object^ sender, EventArgs^ e )
{
// If Sorted is set to true, set it to false;
// otherwise set it to true.
if ( domainUpDown1->Sorted )
{
domainUpDown1->Sorted = false;
}
else
{
domainUpDown1->Sorted = true;
}
}
void domainUpDown1_SelectedItemChanged( Object^ sender, EventArgs^ e )
{
// Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox::Show( String::Concat( "SelectedIndex: ",
domainUpDown1->SelectedIndex.ToString(), "\n", "SelectedItem: ",
domainUpDown1->SelectedItem->ToString() ) );
}
protected DomainUpDown domainUpDown1;
private void MySub()
{
// Create and initialize the DomainUpDown control.
domainUpDown1 = new System.Windows.Forms.DomainUpDown();
// Add the DomainUpDown control to the form.
Controls.Add(domainUpDown1);
}
private void button1_Click(System.Object sender,
System.EventArgs e)
{
// Add the text box contents and initial location in the collection
// to the DomainUpDown control.
domainUpDown1.Items.Add((textBox1.Text.Trim()) + " - " + myCounter);
// Increment the counter variable.
myCounter = myCounter + 1;
// Clear the TextBox.
textBox1.Text = "";
}
private void checkBox1_Click(System.Object sender,
System.EventArgs e)
{
// If Sorted is set to true, set it to false;
// otherwise set it to true.
if (domainUpDown1.Sorted)
{
domainUpDown1.Sorted = false;
}
else
{
domainUpDown1.Sorted = true;
}
}
private void domainUpDown1_SelectedItemChanged(System.Object sender,
System.EventArgs e)
{
// Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox.Show("SelectedIndex: " + domainUpDown1.SelectedIndex.ToString()
+ "\n" + "SelectedItem: " + domainUpDown1.SelectedItem.ToString());
}
Protected domainUpDown1 As DomainUpDown
Private Sub MySub()
' Create and initialize the DomainUpDown control.
domainUpDown1 = New System.Windows.Forms.DomainUpDown()
' Add the DomainUpDown control to the form.
Controls.Add(domainUpDown1)
End Sub
Private Sub button1_Click(sender As System.Object, e As System.EventArgs)
' Add the text box contents and initial location in the collection
' to the DomainUpDown control.
domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter))
' Increment the counter variable.
myCounter = myCounter + 1
' Clear the TextBox.
textBox1.Text = ""
End Sub
Private Sub checkBox1_Click(sender As System.Object, e As System.EventArgs)
' If Sorted is set to true, set it to false;
' otherwise set it to true.
If domainUpDown1.Sorted Then
domainUpDown1.Sorted = False
Else
domainUpDown1.Sorted = True
End If
End Sub
Private Sub domainUpDown1_SelectedItemChanged _
(sender As System.Object, e As System.EventArgs)
' Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _
ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))
End Sub
備註
Object集合可以透過兩種方式建置並提供給 DomainUpDown 控制項使用。 您可以使用 或 Insert 方法,將專案新增至集合 Add 。