DomainUpDown 类

表示显示字符串值的 Windows 数字显示框(也称为 up-down 控件)。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class DomainUpDown
    Inherits UpDownBase
用法
Dim instance As DomainUpDown
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class DomainUpDown : UpDownBase
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class DomainUpDown : public UpDownBase
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class DomainUpDown extends UpDownBase
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class DomainUpDown extends UpDownBase

备注

DomainUpDown 控件显示单个字符串值,该值是通过单击控件的向上或向下按钮从 Object 集合中选定的。除非 ReadOnly 属性设置为 true,否则用户也可以在控件中输入文本(键入的字符串必须匹配集合中的某项才能被接受)。选中某项时,该对象将转换为一个字符串值,以便可显示在数字显示框中。

若要创建要在 DomainUpDown 控件中显示的对象的集合,可以通过使用 AddRemove 方法分别添加或移除这些项。这可在事件处理程序(如按钮的 Click 事件)中调用。通过 Sorted 属性设置为 true,可按字母顺序对对象集合进行排序。当 Wrap 属性设置为 true 时,如果滚动超过了集合中最后一个或第一个对象,列表将分别从第一个或最后一个对象重新开始,但看起来是在连续的列表中滚动。

在代码中或通过单击向上或向下按钮调用 UpButtonDownButton 方法时,将调用 UpdateEditText 来用新字符串更新该控件。如果 UserEdit 设置为 true,则在更新该控件的文本显示之前,该字符串要与集合中的一个值匹配。

示例

下面的代码示例创建并初始化一个 DomainUpDown 控件。该示例允许您设置它的部分属性并创建在数字显示框中显示的字符串集合。该代码假定已经在窗体上实例化了 TextBoxCheckBoxButton。示例还假定已将类级别上的一个成员变量声明为名为 myCounter 的 32 位有符号整数。可在文本框中输入一个字符串,并在单击按钮后将它添加到 Items 集合中。通过单击此复选框,可以切换 Sorted 属性,并观察数字显示框中项集合的变化。

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 'MySub


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 'button1_Click


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 'checkBox1_Click


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 'domainUpDown1_SelectedItemChanged
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:
   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.
    get_Controls().Add(domainUpDown1);
} //MySub

private void button1_Click(Object sender, System.EventArgs e)
{
    // Add the text box contents and initial location in the collection
    // to the DomainUpDown control.
    domainUpDown1.get_Items().Add((textBox1.get_Text().Trim() 
        + " - " + myCounter));

    // Increment the counter variable.
    myCounter = myCounter + 1;

    // Clear the TextBox.
    textBox1.set_Text("");
} //button1_Click

private void checkBox1_Click(Object sender, System.EventArgs e)
{
    // If Sorted is set to true, set it to false; 
    // otherwise set it to true.
    if (domainUpDown1.get_Sorted()) {
        domainUpDown1.set_Sorted(false);
    }
    else {
        domainUpDown1.set_Sorted(true);
    }
} //checkBox1_Click

private void domainUpDown1_SelectedItemChanged(Object sender, 
    System.EventArgs e)
{
    // Display the SelectedIndex and SelectedItem property values in a 
    // MessageBox.
    MessageBox.Show(("SelectedIndex: " 
        + System.Convert.ToString(domainUpDown1.get_SelectedIndex()) 
        + "\n" + "SelectedItem: " 
        + System.Convert.ToString(domainUpDown1.get_SelectedItem())));
} //domainUpDown1_SelectedItemChanged

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ContainerControl
             System.Windows.Forms.UpDownBase
              System.Windows.Forms.DomainUpDown

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、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、1.0

请参见

参考

DomainUpDown 成员
System.Windows.Forms 命名空间
UpDownBase
NumericUpDown