Exforsys

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor

Ads


Home arrow Technical Training arrow VB.NET 2005

DomainUpDown and NumericUpDown Controls

Author : Exforsys Inc.     Published on: 27th Jun 2005    |   Last Updated on: 11th Nov 2008

DomainUpDown and NumericUpDown Controls

DomaiUpDown

The windows Forms System.Windows.DomainUpDown control looks like a combination of a text box and a pair of buttons for moving up or down through a list. This control displays and sets a text string from a list of choices.

Ads

You can select the string by clicking up and down buttons to navigate through a list. Alternatively you can press the UP and DOWN Arrow keys or just type a string that matches an item in the list. You can use this control to select items from an alphabetically sorted list of names. This controls functions like ListBox but it takes up less space comparatively.

We shall look at an example that instantiates an object of DomainUpDown Control programmatically and add values to it.

1. In Visual Basic express start a new Windows Project and give a name as DomainUpDownDemo.

2. Add a text box, a CheckBox and two Buttons.

3. Now add the following code to the form.

Public Class Form1

Protected WithEvents domainUpDown1 As DomainUpDown

Private myCounter As Integer = 1

Private Sub MySub()

domainUpDown1 = New System.Windows.Forms.DomainUpDown()

Controls.Add(domainUpDown1)

End Sub

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

domainUpDown1.Items.Add((TextBox1.Text.Trim() & " - " & myCounter))

myCounter = myCounter + 1

TextBox1.Text = ""

End Sub

Private Sub checkBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

If domainUpDown1.Sorted Then

domainUpDown1.Sorted = False

Else

domainUpDown1.Sorted = True

End If

End Sub

Private Sub domainUpDown1_SelectedItemChanged _

(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles domainUpDown1.SelectedItemChanged

MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _

ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

MySub()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Me.Close()

End Sub

End Class

In the above code you have declared the domainUpDown1 as a variable of DomainUpDown class. In MySub procedure we are instantiating the control with the key word new. The statement “Control.Add(domainUpDown1)” adds the control to the form.

The Button1 Click event reads the value from TextBox, appends a number to it and adds the string to the domainUpDown1 object. Press F5 to execute the program. This following window will be shown. Type values into the TextBox and click the button “Add Strings” to add the values to the domainUpDown1 object.

The event handler for the donainUpDown1 object gives the message box that is shown below:

This control can be used in the place of the ListBox control where less space is needed.

NumericUpDown

This Windows Forms System.Windows.Forms.NumericUpDown control looks like a combination of a text box and a pair of arrows that the user can click to adjust a value. The control displays and sets a single numeric value from a list of choices.

The user can increment and decrement the number by clicking up and down buttons, by pressing the UP and DOWN ARROW keys, or by typing a number. Clicking the UP ARROW key moves the value toward the maximum; clicking the DOWN ARROW key moves the value toward the minimum. An example where this kind of control might be useful is for a volume control on a music player. Numeric up-down controls are used in many Windows control panel applications.

The following Demo illustrates the use of this control.

1. In the Visual Studio IDE create a new windows project and give the name NumericUpDownDemo.

2. To the Form1 add a NumericUpdownControl, a list box and a button.

3. Right click the form and choose View Codes from the context sensitive menu.

4. Now add the following codes to the Form1.

Ads

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.Close()

End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged

Label1.Text = "The current Value of the counter is : " & NumericUpDown1.Value

End Sub

End Class

Press F5 to execute the program. When you click the UP and Down Arrow in the NumricUpDown1 object, the text on the Label will show the value of the counter. This is shown in the screen shot below:

You can also set the number of decimal places that will appear after the decimal point. The default is zero. You can also set the thousands separator. This control can also be set up to display hexadecimal value by setting the value of System.Windows.Forms.NumericUpDown.Hexadecimal property true.



 
This tutorial is part of a VB.NET 2005 tutorial series. Read it from the beginning and learn yourself.

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor
 

Comments