
Originally Posted by
samqweqwe3
do you know how to keep it in the from thou because when i test it sometimes i have to wait ages for it to come back at the player.
Moving and resizing controls is slow and not recommended, but if you want to do it that way try doing the math using variables first then set the control properties only once. On my PC the code in button1 took close to 300ms to complete while the code in button2 took less then 0.35ms...
Code:
Private rnd1 As New Random
Private rnd2 As New Random
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim sw As Stopwatch = Stopwatch.StartNew
' simulate 1000 calcs
For i As Integer = 1 To 1000
PbxMet.Top = rnd1.Next(Me.Height - PbxMet.Height)
PbxMet.Width = rnd2.Next(Me.Height - PbxMet.Height)
If PbxMet.Width >= 100 Then
PbxMet.Width = rnd2.Next(Me.Height - PbxMet.Height)
End If
PbxMet.Height = PbxMet.Width
Next
' show elapsed time
sw.Stop()
Debug.Print((sw.ElapsedTicks / Stopwatch.Frequency * 1000).ToString("0.00"))
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim sw As Stopwatch = Stopwatch.StartNew
' Save control props to variables
Dim pTop As Integer = PbxMet.Top
Dim pWidth As Integer = PbxMet.Width
' do the math, simulate 1000 calcs
For i As Integer = 1 To 1000
pTop = rnd1.Next(Me.Height - PbxMet.Height)
pWidth = rnd2.Next(Me.Height - PbxMet.Height)
If pWidth >= 100 Then
pWidth = rnd2.Next(Me.Height - PbxMet.Height)
End If
Next
' set control props
PbxMet.Top = pTop
PbxMet.Size = New Size(pWidth, pWidth)
' show elapsed time
sw.Stop()
Debug.Print((sw.ElapsedTicks / Stopwatch.Frequency * 1000).ToString("0.00"))
End Sub