Share numericupdown vb.net,

phamdiep1qwerty

New member
#Numericupdown #vb.net #Control #tutorial #Programming ## numericupdown trong vb.net

Điều khiển NumericUpdown là điều khiển Windows Forms cho phép người dùng chọn một số từ một loạt các giá trị.Nó tương tự như một điều khiển thanh trượt, nhưng với khả năng được thêm vào một giá trị.Các điều khiển Numericupdown thường được sử dụng để cho phép người dùng chỉ định giá trị, chẳng hạn như tỷ lệ phần trăm hoặc một số mục.

Để tạo điều khiển NumericUpdown trong VB.NET, bạn có thể sử dụng mã sau:

`` `VBNet
Dim NumupDown1 dưới dạng new Numericupdown ()
NumupDown1.location = New Point (10, 10)
numupdown1.width = 100
numupdown1.minimum = 0
NumupDown1.Maximum = 100
numupdown1.value = 50
Me.controls.add (numupdown1)
`` `

Mã này sẽ tạo ra một điều khiển NumericUpdown ở góc trên cùng bên trái của biểu mẫu.Điều khiển sẽ có chiều rộng 100 pixel và phạm vi giá trị từ 0 đến 100. Giá trị ban đầu của điều khiển sẽ là 50.

Bạn có thể liên kết điều khiển Numericupdown với thuộc tính của biểu mẫu hoặc lớp của bạn để theo dõi giá trị mà người dùng chọn.Để làm điều này, bạn có thể sử dụng mã sau:

`` `VBNet
numupdown1.valuechanged += _
EventHandler mới (Địa chỉ Numupdown1_ValueChanged)
`` `

Mã này sẽ đính kèm một trình xử lý sự kiện vào sự kiện có giá trị của NumericPown Control.Trình xử lý sự kiện sẽ được gọi bất cứ khi nào người dùng thay đổi giá trị của điều khiển.

Trong bộ xử lý sự kiện, bạn có thể cập nhật thuộc tính mà bạn đang ràng buộc điều khiển.Ví dụ: mã sau sẽ cập nhật thuộc tính văn bản của điều khiển nhãn lên giá trị của điều khiển NumericUpdown:

`` `VBNet
Sub NumupDown1_ValueChanged (người gửi là đối tượng, e là EventArgs)
lblvalue.text = numupdown1.value.toString ()
Kết thúc phụ
`` `

## Thuộc tính điều khiển Numericupdown

Điều khiển Numericupdown có một số thuộc tính mà bạn có thể sử dụng để tùy chỉnh sự xuất hiện và hành vi của nó.Những thuộc tính này bao gồm:

*** Vị trí ** - Vị trí của điều khiển trên biểu mẫu.
*** chiều rộng ** - chiều rộng của điều khiển.
*** Tối thiểu ** - Giá trị tối thiểu mà điều khiển có thể hiển thị.
*** tối đa ** - giá trị tối đa mà điều khiển có thể hiển thị.
*** Giá trị ** - Giá trị hiện tại của điều khiển.
*** Tăng ** - Số tiền mà giá trị của điều khiển thay đổi khi người dùng nhấp vào mũi tên lên hoặc xuống.
*** Textalign ** - Sự liên kết của văn bản hiển thị giá trị của điều khiển.
*** Phông chữ ** - Phông chữ được sử dụng để hiển thị văn bản của điều khiển.
*** BackColor ** - Màu nền của điều khiển.
*** PORTOLOLOR ** - Màu tiền cảnh của văn bản của điều khiển.

## Sự kiện điều khiển Numericupdown

Điều khiển Numericupdown có một số sự kiện mà bạn có thể sử dụng để theo dõi tương tác của người dùng với điều khiển.Những sự kiện này bao gồm:

*** ValueChanged ** - Sự kiện này được nêu ra khi người dùng thay đổi giá trị của điều khiển.
*** Mouseenter ** - Sự kiện này được nâng lên khi con trỏ chuột đi vào điều khiển.
*** mouseleave ** - Sự kiện này được nâng lên khi con trỏ chuột rời khỏi điều khiển.
*** mousedown ** - Sự kiện này được nêu ra khi người dùng nhấp vào điều khiển.
*** Mouseup ** - Sự kiện này được nâng lên khi người dùng phát hành nút chuột qua điều khiển.

## Phần kết luận

Điều khiển NumericUpdown là một điều khiển linh hoạt có thể được sử dụng để cho phép người dùng chọn một số từ một loạt các giá trị.Thật dễ dàng để tạo và sử dụng, và nó cung cấp một số thuộc tính và sự kiện mà bạn có thể sử dụng để tùy chỉnh ngoại hình và hành vi của nó.
=======================================
#Numericupdown #vb.net #Control #tutorial #Programming ## NumericUpDown in VB.NET

A NumericUpDown control is a Windows Forms control that allows the user to select a number from a range of values. It is similar to a Slider control, but with the added ability to type in a value. NumericUpDown controls are often used to allow the user to specify a value, such as a percentage or a number of items.

To create a NumericUpDown control in VB.NET, you can use the following code:

```vbnet
Dim numUpDown1 As New NumericUpDown()
numUpDown1.Location = New Point(10, 10)
numUpDown1.Width = 100
numUpDown1.Minimum = 0
numUpDown1.Maximum = 100
numUpDown1.Value = 50
Me.Controls.Add(numUpDown1)
```

This code will create a NumericUpDown control at the top-left corner of the form. The control will have a width of 100 pixels and a range of values from 0 to 100. The initial value of the control will be 50.

You can bind the NumericUpDown control to a property of your form or class to track the value that the user selects. To do this, you can use the following code:

```vbnet
numUpDown1.ValueChanged += _
New EventHandler(AddressOf numUpDown1_ValueChanged)
```

This code will attach an event handler to the NumericUpDown control's ValueChanged event. The event handler will be called whenever the user changes the value of the control.

In the event handler, you can update the property that you are binding the control to. For example, the following code would update the Text property of a Label control to the value of the NumericUpDown control:

```vbnet
Private Sub numUpDown1_ValueChanged(sender As Object, e As EventArgs)
lblValue.Text = numUpDown1.Value.ToString()
End Sub
```

## NumericUpDown Control Properties

The NumericUpDown control has a number of properties that you can use to customize its appearance and behavior. These properties include:

* **Location** - The location of the control on the form.
* **Width** - The width of the control.
* **Minimum** - The minimum value that the control can display.
* **Maximum** - The maximum value that the control can display.
* **Value** - The current value of the control.
* **Increment** - The amount by which the value of the control changes when the user clicks the up or down arrow.
* **TextAlign** - The alignment of the text that displays the value of the control.
* **Font** - The font that is used to display the text of the control.
* **BackColor** - The background color of the control.
* **ForeColor** - The foreground color of the text of the control.

## NumericUpDown Control Events

The NumericUpDown control has a number of events that you can use to track the user's interaction with the control. These events include:

* **ValueChanged** - This event is raised when the user changes the value of the control.
* **MouseEnter** - This event is raised when the mouse cursor enters the control.
* **MouseLeave** - This event is raised when the mouse cursor leaves the control.
* **MouseDown** - This event is raised when the user clicks the control.
* **MouseUp** - This event is raised when the user releases the mouse button over the control.

## Conclusion

The NumericUpDown control is a versatile control that can be used to allow the user to select a number from a range of values. It is easy to create and use, and it provides a number of properties and events that you can use to customize its appearance and behavior.
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top