NumericUpDown and DomainUpDown control in VB.NET

In this article we demonstrate what is NumericUpDown and DomainUpDown Control and how to use both the Controls
  • 5818
 

A visual basic NumericUpDown control is said to be a pair of a TextBox Control and the Up Down arrows. The NumericUpDown Control generally works as a counter in which a user can input a numeric value. It is also called a Spin box. The arrow in the NumericUpDown Control works for increase or decrease the value. Up arrow is for increase the value and down arrow is for decrease the value. If you hold the mouse on the up arrow it will increase the value till the maximum value in the list and then stop. Its reverse condition is works with the down arrowthe Specific range is also defined for the values. The example for the NumericUpDown Control is the Volume control in any Music Player. 

The below example shows the use of NumericUpDown control:-

  • Create a new Project 
  • Add a NumericUpDown control, a Label and a Button. The form will look like below.

    NumericUpDown1.gif
     
  • Add the below code to the form.

    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs)Handles
            
    Button1.Click
            Me.Close()
        End Sub
        Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.ObjectByVal eAs System.EventArgs)
        Handles
     NumericUpDown1.ValueChanged
            Label1.Text = "The current Value of the counter is : " & NumericUpDown1.Value
        End 
    Sub
    End Class

    Output:-

    NumericUpDown2.gif

    DomainUpDown Control:-

    DomainUpDown control is used to allow user to move up or down to a particular value. It shows a textbox and up and down arrow that allows user to move between its valuesTheDomainUpDown control Shows and sets a text string from a given list of choices. If you want to select a string you can do this by up and down buttonand also by typing the string in the TextBox that matches the string in the list.

    The below example shows the use of DomainUpDown control:-
     
  • Create a new project. 
  • Add TextBox, CheckBox and two Buttons than form will look like below.

    DomainUpDown3.gif
     
  • Add the Below code to the form.

    Protected WithEvents domainUpDown As DomainUpDown
     
            Private myCounter As Integer = 1
             Private Sub MySub()
             domainUpDown = New System.Windows.Forms.DomainUpDown()
             Controls.Add(domainUpDown)
             End Sub
     
            Private Sub button1_Click(ByVal sender As System.ObjectByVal e AsSystem.EventArgsHandles
             
    Button1.Click
             domainUpDown.Items.Add((TextBox1.Text.Trim() & " - " & myCounter))
                 myCounter = myCounter + 1
                 TextBox1.Text = ""
     
            End Sub
     
            Private Sub checkBox1_Click(ByVal sender As System.ObjectByVal e AsSystem.EventArgsHandles
             
    CheckBox1.CheckedChanged
             If domainUpDown.Sorted Then
     
                domainUpDown.Sorted = False
     
            Else
     
                domainUpDown.Sorted = True
     
            End If
     
            End Sub
     
            Private Sub domainUpDown_SelectedItemChanged_(ByVal sender As System.Object,ByVal e As
             
    System.EventArgs)
             MessageBox.Show(("SelectedIndex: " & domainUpDown.SelectedIndex.ToString() & _
             ControlChars.Cr & "SelectedItem: " & domainUpDown.SelectedItem.ToString()))
             End Sub
     
            Private Sub Form1_Load(ByVal sender As System.ObjectByVal e AsSystem.EventArgsHandles
             MyBase
    .Load
                 MySub()
             End Sub
     
            Private Sub Button2_Click(ByVal sender As System.ObjectByVal e AsSystem.EventArgsHandles
                 
    Button2.Click
                 Me.Close()
             End 
    Sub


    Output:-

    DomainUpDown4.gif

    DomainUpDown5.gif


      

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.