Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to assign a value to a location.x of a picturebox programmatically? 1

Status
Not open for further replies.

Antzelinaki

Programmer
Jun 16, 2012
14
Hello!!!
I have created an array of pictureboxes named pbs. Public pbs(8) As PictureBox
And the what I want to do is to assign a different specific value for Location.X and Location.Y programmatically for each element. x,y are variables that change their values for each element programmatically.

for example

for i=0 to 7
pbs(i).Location.X = x
pbs(i).Location.Y = y​
next i

Unfortunately I am getting this error Expression is a value and therefore cannot be the target of an assignment.
before to run it. So, is there a way to do it and how??? Any help will be much appreciated.
 
Use the Left and Top properties to set the X and Y, respectively:

for i=0 to 7
pbs(i).Left = x
pbs(i).Top = y
next i

0,0 is the upper-left corner of the container (e.g., form, panel, tab control, etc.)

You can also do:

for i=0 to 7
pbs(i).Location = New Point(x, y)
next i

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you so much jebenson. The second way works for me :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top