locked
Center Screen RRS feed

  • Question

  •  One thing how would you click on a picturebox and have multiple Picturebox move to center of screen??
    Sunday, September 21, 2008 5:46 PM

Answers

  •  
    PictureBox1.Width = 100  
            PictureBox1.Height = 100  
            PictureBox2.Width = 100  
            PictureBox2.Height = 100  
            PictureBox3.Width = 100  
            PictureBox3.Height = 100  
            PictureBox4.Width = 100  
            PictureBox4.Height = 100  
            PictureBox5.Width = 100  
            PictureBox5.Height = 100  
            PictureBox6.Width = 100  
            PictureBox6.Height = 100  
            PictureBox7.Width = 100  
            PictureBox7.Height = 100  
            PictureBox8.Width = 100  
            PictureBox8.Height = 100  
            PictureBox9.Width = 100  
            PictureBox9.Height = 100  
            PictureBox10.Width = 100  
            PictureBox10.Height = 100  
            PictureBox11.Width = 100  
            PictureBox11.Height = 100  
            PictureBox12.Width = 100  
            PictureBox12.Height = 100  
            PictureBox13.Width = 100  
            PictureBox13.Height = 100  
            PictureBox14.Width = 100  
            PictureBox14.Height = 100  
            PictureBox15.Width = 100  
            PictureBox15.Height = 100  
            PictureBox16.Width = 100  
            PictureBox16.Height = 100  
     
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None  
            PictureBox1.Left = ((Me.Width / 2) - (PictureBox1.Width))  
            PictureBox1.Top = ((Me.Height / 2) - (PictureBox1.Height))  
     
            PictureBox2.Left = ((Me.Width / 2))  
            PictureBox2.Top = ((Me.Height / 2) - (PictureBox2.Height))  
     
            PictureBox3.Left = ((Me.Width / 2) - (PictureBox3.Width))  
            PictureBox3.Top = ((Me.Height / 2))  
     
            PictureBox4.Left = ((Me.Width / 2))  
            PictureBox4.Top = ((Me.Height / 2))  
     
            PictureBox5.Left = ((Me.Width / 2) - (PictureBox1.Width + PictureBox5.Width))  
            PictureBox5.Top = ((Me.Height / 2) - (PictureBox1.Height + PictureBox5.Height))  
     
            PictureBox6.Left = ((Me.Width / 2) - (PictureBox1.Width + PictureBox6.Width))  
            PictureBox6.Top = ((Me.Height / 2) - (PictureBox1.Height))  
     
            PictureBox7.Left = ((Me.Width / 2) - (PictureBox1.Width))  
            PictureBox7.Top = ((Me.Height / 2) - (PictureBox1.Height + PictureBox7.Height))  
     
            PictureBox8.Left = ((Me.Width / 2) + (PictureBox3.Width))  
            PictureBox8.Top = ((Me.Height / 2) + (PictureBox3.Height))  
     
            PictureBox9.Left = ((Me.Width / 2) + (PictureBox3.Width))  
            PictureBox9.Top = ((Me.Height / 2))  
     
            PictureBox10.Left = ((Me.Width / 2))  
            PictureBox10.Top = ((Me.Height / 2) + (PictureBox3.Height))  
     
            PictureBox11.Left = ((Me.Width / 2) + (PictureBox2.Width))  
            PictureBox11.Top = ((Me.Height / 2) - (PictureBox2.Height + PictureBox11.Height))  
     
            PictureBox12.Left = ((Me.Width / 2) + (PictureBox2.Width))  
            PictureBox12.Top = ((Me.Height / 2) - (PictureBox2.Height))  
     
            PictureBox13.Left = ((Me.Width / 2))  
            PictureBox13.Top = ((Me.Height / 2) - (PictureBox2.Height + PictureBox13.Height))  
     
            PictureBox14.Left = ((Me.Width / 2) - (PictureBox4.Width))  
            PictureBox14.Top = ((Me.Height / 2) + (PictureBox4.Height))  
     
            PictureBox15.Left = ((Me.Width / 2) - (PictureBox4.Width + PictureBox15.Height))  
            PictureBox15.Top = ((Me.Height / 2) + (PictureBox4.Height))  
     
            PictureBox16.Left = ((Me.Width / 2) - (PictureBox4.Width + PictureBox16.Height))  
            PictureBox16.Top = ((Me.Height / 2))  
     
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable 


    There, all 16.

    It's just a matter of moving them over one more picture width. (The picture can be any size/shape as long as it's consistent)
    • Proposed as answer by joebobfrank Sunday, September 21, 2008 8:27 PM
    • Marked as answer by VB King Dracitus Sunday, September 21, 2008 8:44 PM
    Sunday, September 21, 2008 8:23 PM

All replies

  • would you want them to move on top of each other?

    here is how you would do it for 1 picture, just repeat it a bunch of times (changing picturebox1 to whatever object you want) for multiple objects.




    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None  
            PictureBox1.Left = ((Me.Width / 2) - (PictureBox1.Width / 2))  
            PictureBox1.Top = ((Me.Height / 2) - (PictureBox1.Height / 2))  
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable 


    (You have to take the borders off to center it, because visual basic counts the borders in the program's width making the picture look way off center.)
    • Edited by joebobfrank Sunday, September 21, 2008 6:04 PM
    Sunday, September 21, 2008 6:03 PM
  • id like to try for a 4 by 4 grid of picture boxs but ill try your code
    Sunday, September 21, 2008 6:17 PM
  •  
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None     
            PictureBox1.Left = ((Me.Width / 2) - (PictureBox1.Width))     
            PictureBox1.Top = ((Me.Height / 2) - (PictureBox1.Height))    
     PictureBox2.Left = ((Me.Width / 2) + (PictureBox2.Width))     
            PictureBox2.Top = ((Me.Height / 2) - (PictureBox2.Height))  
     PictureBox3.Left = ((Me.Width / 2) - (PictureBox3.Width))     
            PictureBox3.Top = ((Me.Height / 2) + (PictureBox3.Height))  
    PictureBox4.Left = ((Me.Width / 2) + (PictureBox4.Width))     
            PictureBox4.Top = ((Me.Height / 2) + (PictureBox4.Height))  
       
        
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable    
     

    That should make a 2 by 2 grid in the middle, but you can easily expand on that.
    Sunday, September 21, 2008 6:30 PM
  • Could you Explain the code to me im not understanding what it does
    it works it just puts the pictureboxes there but in a 3 by 3 grid with only the corners showing
    an explnation would be great thank you for your time
    Sunday, September 21, 2008 6:46 PM
  • oh sorry, didn't test that out. This will work much better:

    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None  
            PictureBox1.Left = ((Me.Width / 2) - (PictureBox1.Width))  
            PictureBox1.Top = ((Me.Height / 2) - (PictureBox1.Height))  
            PictureBox2.Left = ((Me.Width / 2))  
            PictureBox2.Top = ((Me.Height / 2) - (PictureBox2.Height))  
            PictureBox3.Left = ((Me.Width / 2) - (PictureBox3.Width))  
            PictureBox3.Top = ((Me.Height / 2))  
            PictureBox4.Left = ((Me.Width / 2))  
            PictureBox4.Top = ((Me.Height / 2))  
     
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable 

    What it does is set the left edge to the middle of the form, and the top to center as well.
    Sunday, September 21, 2008 7:39 PM
  • much better thanks
    Sunday, September 21, 2008 7:42 PM
  • Could You Show me how i would add on to that and i was wounding if you would explain the code to me please
    Sunday, September 21, 2008 7:49 PM
  •  That's pretty much as straight forward as it gets...

    The middle of the screen would be where form width / 2 and for height /2 meet.

    So you set the left edge of the picturebox to the middle of the screen minus the width of the picture (so that the right edge is in the middle of the screen) then you just flip signs and whatnot to move the picture around the midpoint.

    I'll try and mod it for 16 pictures.
    Sunday, September 21, 2008 7:56 PM
  • Thank you i was useing wired size for form and picturebox but now i set my form to 500,500 and my picturebox to 100,100

    So its like this


    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

    PictureBox1.Left = ((Me.Width / 5) - (PictureBox1.Width))

    PictureBox1.Top = ((Me.Height / 5) - (PictureBox1.Height))





    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable



    So then i just change the number acccorinly to the size of the form and the size of the picturebox
    so 5 h and 5 w is top left 1 h and 1 w is bottom right ??

    Sunday, September 21, 2008 8:03 PM
  •  
    PictureBox1.Width = 100  
            PictureBox1.Height = 100  
            PictureBox2.Width = 100  
            PictureBox2.Height = 100  
            PictureBox3.Width = 100  
            PictureBox3.Height = 100  
            PictureBox4.Width = 100  
            PictureBox4.Height = 100  
            PictureBox5.Width = 100  
            PictureBox5.Height = 100  
            PictureBox6.Width = 100  
            PictureBox6.Height = 100  
            PictureBox7.Width = 100  
            PictureBox7.Height = 100  
            PictureBox8.Width = 100  
            PictureBox8.Height = 100  
            PictureBox9.Width = 100  
            PictureBox9.Height = 100  
            PictureBox10.Width = 100  
            PictureBox10.Height = 100  
            PictureBox11.Width = 100  
            PictureBox11.Height = 100  
            PictureBox12.Width = 100  
            PictureBox12.Height = 100  
            PictureBox13.Width = 100  
            PictureBox13.Height = 100  
            PictureBox14.Width = 100  
            PictureBox14.Height = 100  
            PictureBox15.Width = 100  
            PictureBox15.Height = 100  
            PictureBox16.Width = 100  
            PictureBox16.Height = 100  
     
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None  
            PictureBox1.Left = ((Me.Width / 2) - (PictureBox1.Width))  
            PictureBox1.Top = ((Me.Height / 2) - (PictureBox1.Height))  
     
            PictureBox2.Left = ((Me.Width / 2))  
            PictureBox2.Top = ((Me.Height / 2) - (PictureBox2.Height))  
     
            PictureBox3.Left = ((Me.Width / 2) - (PictureBox3.Width))  
            PictureBox3.Top = ((Me.Height / 2))  
     
            PictureBox4.Left = ((Me.Width / 2))  
            PictureBox4.Top = ((Me.Height / 2))  
     
            PictureBox5.Left = ((Me.Width / 2) - (PictureBox1.Width + PictureBox5.Width))  
            PictureBox5.Top = ((Me.Height / 2) - (PictureBox1.Height + PictureBox5.Height))  
     
            PictureBox6.Left = ((Me.Width / 2) - (PictureBox1.Width + PictureBox6.Width))  
            PictureBox6.Top = ((Me.Height / 2) - (PictureBox1.Height))  
     
            PictureBox7.Left = ((Me.Width / 2) - (PictureBox1.Width))  
            PictureBox7.Top = ((Me.Height / 2) - (PictureBox1.Height + PictureBox7.Height))  
     
            PictureBox8.Left = ((Me.Width / 2) + (PictureBox3.Width))  
            PictureBox8.Top = ((Me.Height / 2) + (PictureBox3.Height))  
     
            PictureBox9.Left = ((Me.Width / 2) + (PictureBox3.Width))  
            PictureBox9.Top = ((Me.Height / 2))  
     
            PictureBox10.Left = ((Me.Width / 2))  
            PictureBox10.Top = ((Me.Height / 2) + (PictureBox3.Height))  
     
            PictureBox11.Left = ((Me.Width / 2) + (PictureBox2.Width))  
            PictureBox11.Top = ((Me.Height / 2) - (PictureBox2.Height + PictureBox11.Height))  
     
            PictureBox12.Left = ((Me.Width / 2) + (PictureBox2.Width))  
            PictureBox12.Top = ((Me.Height / 2) - (PictureBox2.Height))  
     
            PictureBox13.Left = ((Me.Width / 2))  
            PictureBox13.Top = ((Me.Height / 2) - (PictureBox2.Height + PictureBox13.Height))  
     
            PictureBox14.Left = ((Me.Width / 2) - (PictureBox4.Width))  
            PictureBox14.Top = ((Me.Height / 2) + (PictureBox4.Height))  
     
            PictureBox15.Left = ((Me.Width / 2) - (PictureBox4.Width + PictureBox15.Height))  
            PictureBox15.Top = ((Me.Height / 2) + (PictureBox4.Height))  
     
            PictureBox16.Left = ((Me.Width / 2) - (PictureBox4.Width + PictureBox16.Height))  
            PictureBox16.Top = ((Me.Height / 2))  
     
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable 


    There, all 16.

    It's just a matter of moving them over one more picture width. (The picture can be any size/shape as long as it's consistent)
    • Proposed as answer by joebobfrank Sunday, September 21, 2008 8:27 PM
    • Marked as answer by VB King Dracitus Sunday, September 21, 2008 8:44 PM
    Sunday, September 21, 2008 8:23 PM
  • Thank you i think im getting it thanks
    Sunday, September 21, 2008 8:30 PM