Windows Application Form with PictureBox and Scalling Issues

~OSD~ 2,201 Reputation points
2024-01-07T21:21:28.1833333+00:00

WARNING! There was an error parsing the document

Hi,

I have a visual basic Windows Forms application.

Form1 has one PictureBox, PictureBox1.

**Problem Description:** When this application is used on different screen resolutions the picture box /picture shows the wrong position.

What I have done so far is to configure the Form1 properties AutoScaleMode=DPI

PictureBox properties are shown below, anything need to be changed /adjusted?  
Or how to configure the picturebox that if the resolution changes, it remain in a good position.  
  
![User's image]()

Developer technologies .NET Other
Developer technologies VB
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-01-08T05:52:32.9166667+00:00

    Hi @~OSD~ ,

    You can handle the Resize event of the form and adjust the position of the PictureBox accordingly

    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
        CenterPictureBox()
    End Sub
    
    Private Sub CenterPictureBox()
        PictureBox1.Left = (Me.ClientSize.Width - PictureBox1.Width) \ 2
        PictureBox1.Top = (Me.ClientSize.Height - PictureBox1.Height) \ 2
    End Sub
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.