VB-NET How to give a new location to a control ?, with a value of variable

1

That's personal.

I have this code to define a New Point for a PictureBox, but at the time of running it does not work, and it is even obvious why not, will know in the code below ...

Dim VarPbx As String = "PictureBox" & "2" 
Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)    
Dim ValorLocation As String = "324, 212"

pbx.Location = New Point(ValorLocation)

Discovered? I'm a layman myself '-'

I've tried other types of variables for (ValorLocation) but it's the expected error in some of the numbers, the right one is the value Decimal, right? Thank you for opening this post.

    
asked by anonymous 05.05.2018 / 04:37

1 answer

1

It's simple: you're passing a string as an argument to build a new Point , and the correct build is (int, int) .

See the example:

Dim VarPbx As String = "PictureBox" & "2"

Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)

Dim ValorLocationX As Integer = 324
Dim ValorLocationY As Integer = 212

pbx.Location = New Point(ValorLocationX, ValorLocationY)

In addition, you do not need this to call a member by its name:

Dim VarPbx As String = "PictureBox" & "2"

Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)

You can simplify with:

Dim VarPbx As PictureBox = Me.PictureBox2

Read about instructions , a href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/parameters-and-arguments"> parameters and data types . =)

    
05.05.2018 / 04:54