none
how can I make all buttons in the middle of screen?

    Question

  • Hello, I have a forum that has about 6 buttons, and when It opens in full screen its not in the middle of it, how can I center all the buttons, so they can all line up in small screen and full screen. Thank you

    Monday, May 1, 2017 8:33 PM

Answers

  • Place them into a panel then use the following to center the panel. It's not exact but close enough as I don't take into consideration the taskbar.

    Public Class Form1
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            Panel1.Location = New Point((Width \ 2) - (Panel1.Width \ 2), (Height \ 2) - (Panel1.Height \ 2))
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by amjrl Monday, May 1, 2017 11:28 PM
    Monday, May 1, 2017 10:20 PM
    Moderator

All replies

  • Amjrl,

    Take a look at the "anchor" properties.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(v=vs.110).aspx

    sample code and explanation is on that page


    Success
    Cor

    Monday, May 1, 2017 9:05 PM
  • Place them into a panel then use the following to center the panel. It's not exact but close enough as I don't take into consideration the taskbar.

    Public Class Form1
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            Panel1.Location = New Point((Width \ 2) - (Panel1.Width \ 2), (Height \ 2) - (Panel1.Height \ 2))
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by amjrl Monday, May 1, 2017 11:28 PM
    Monday, May 1, 2017 10:20 PM
    Moderator
  • Hello, I have a forum that has about 6 buttons, and when It opens in full screen its not in the middle of it, how can I center all the buttons, so they can all line up in small screen and full screen. Thank you

    If you could show an image of the form both small and full screen and how you want it to appear, that would be helpful. Use the rightmost icon (mountains with the sun) to upload images.

    As an experiment, I created a form, added a Panel, and added 6 buttons to the panel, then resized the panel until the buttons were centered in it. Added one line of code to the Form Resize sub:

        Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
            Panel1.Location = New Point((Me.ClientRectangle.Width \ 2) - (Panel1.Width \ 2), (Me.ClientRectangle.Height \ 2) - (Panel1.Height \ 2))
        End Sub
    

    This may be needed also.

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Button1.Parent = Panel1
            Button2.Parent = Panel1
            Button3.Parent = Panel1
            Button4.Parent = Panel1
            Button5.Parent = Panel1
            Button6.Parent = Panel1
        End Sub

    As Cor stated, the anchor property may solve your question also.

    Monday, May 1, 2017 10:37 PM