1

I have GUI which is split in two pieces using a SplitContainer Control.
One part is a navigation Panel, the other a workspace Panel.

When I open the app, on start-up a new Form appears (using ShowDialog()), to welcomes Users. I would like to show it centered in the middle of the workspace Panel.

Is there anybody who knows how to solve this?

 Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     frmWelcome.ShowDialog()
 End Sub
Jimi
  • 29,621
  • 8
  • 43
  • 61
  • Show us some code (how you open that form) to get some help. – PavlinII Apr 18 '18 at 11:48
  • @PavlinII i added but i don't know is it useful for you?. frmWelcome opens at the center of MainForm. Main form also has a panel named pnlWorkspace i would like to open new form (frmWelcome) at the center of pnlWorkspace. –  Apr 18 '18 at 12:04

2 Answers2

2

Assuming that Panel2 is your WorkSpace Panel, use its PointToScreen() method to calculate the Screen coordinates of frmWelcome and position it in the middle.

Be sure to set your frmWelcome.StartPosition = Manual, in the Designer or in its Constructor.

Here, I'm using the Shown event, to be sure that the pre-set positions in MainForm are already set.

Private Sub MainForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    Dim p As Point = New Point(
        ((SplitContainer1.Panel2.ClientSize.Width) \ 2) - frmWelcome.Width \ 2,
        ((SplitContainer1.Panel2.ClientSize.Height) \ 2) - frmWelcome.Height \ 2)

    frmWelcome.Location = SplitContainer1.Panel2.PointToScreen(p)
    frmWelcome.ShowDialog()
End Sub
Jimi
  • 29,621
  • 8
  • 43
  • 61
0

You can use the properties on forms to do this.

set the frmWelcome form property StartPosition to CenterScreen.

If you want it center of the screen opening it, you will have to setup MDI but from there you can do frmWelcome.ShowDialog(Me) and set the property StartPosition to CenterParent.

Hope this helps!

Sasha
  • 1,674
  • 1
  • 16
  • 23