1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Public Class Form1
Private WithEvents numeric As New NumericUpDown
Private label1 As New Label
Private Sub init()
With numeric
.Font = New Font("arial", 14, FontStyle.Bold)
.Maximum = 1000000
.Minimum = 1
.Location = New Point(10, 10)
.Width = 50
End With
Me.Controls.Add(numeric)
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.WindowState = FormWindowState.Maximized
init()
End Sub
Private Sub numeric_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles numeric.KeyUp
Dim random As New Random
Dim x, y As Integer
x = random.Next(10, Me.Width - DirectCast(sender, NumericUpDown).Width)
y = random.Next(10, Me.Height - DirectCast(sender, NumericUpDown).Height)
DirectCast(sender, NumericUpDown).Location = New Point(x, y)
End Sub
Private Sub numeric_ValueChanged(sender As Object, e As System.EventArgs) Handles numeric.ValueChanged
Dim random As New Random
Dim x, y As Integer
x = random.Next(10, Me.Width - DirectCast(sender, NumericUpDown).Width)
y = random.Next(10, Me.Height - DirectCast(sender, NumericUpDown).Height)
DirectCast(sender, NumericUpDown).Location = New Point(x, y)
End Sub
End Class |
Partager