Re: Position of a PictureBox
Re: Position of a PictureBox
If you add an image in Quick Reply, it doesn't show up. You'd have to Go Advanced.
However, your math doesn't seem so bad, so you probably need to look at a few other things first. Is the form really the size you are expecting it to be? Probably not. I think that DPI scaling may influence the actual size.
Re: Position of a PictureBox
This looks correct,
Code:
Public Class Form1
Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
CenterPB1()
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
CenterPB1()
End Sub
Private Sub CenterPB1()
PictureBox1.Left = (Me.ClientSize.Width - PictureBox1.Width) \ 2
PictureBox1.Top = (Me.ClientSize.Height - PictureBox1.Height) \ 2
Label1.Text = String.Format("W:{0} H:{1}", PictureBox1.Width, PictureBox1.Height)
Label2.Text = String.Format("W:{0} H:{1}", Me.ClientSize.Width, Me.ClientSize.Height)
End Sub
End Class
Re: Position of a PictureBox
try
Code:
PictureBox1.Left = (Me.ClientSize.Width/2) - (PictureBox1.Width/ 2)
PictureBox1.Top = (Me.ClientSize.Height/2) - (PictureBox1.Height/ 2)
also dont forget that if on a laptop sometimes the scaling is 125% so need to take in to account that
Re: Position of a PictureBox
Quote:
Originally Posted by
k_zeon
try
Code:
PictureBox1.Left = (Me.ClientSize.Width/2) - (PictureBox1.Width/ 2)
PictureBox1.Top = (Me.ClientSize.Height/2) - (PictureBox1.Height/ 2)
also dont forget that if on a laptop sometimes the scaling is 125% so need to take in to account that
Did you see Post #4?
Re: Position of a PictureBox
thanks for your answer but i think i found my problem :
me.size is the size of the external dimensions of the form and the (0,0) location for the picturebox is inside the form
Re: Position of a PictureBox
Quote:
Originally Posted by
Grenoblus
thanks for your answer but i think i found my problem :
me.size is the size of the external dimensions of the form and the (0,0) location for the picturebox is inside the form
You’re right. Size (or the Bounds rectangle) is not the same as ClientSize (or the ClientRectangle)