title: Center form on screen or on parent
body: <p>Since built in functionality for positioning forms in VB.NET are not always suitable to use I try to make my sub to do that.</p>
  
  <p>But I missed something...</p>
  
  <pre><code>Public Sub form_center(ByVal frm As Form, Optional ByVal parent As Form = Nothing)
  
      Dim x As Integer
      Dim y As Integer
      Dim r As Rectangle
  
      If Not parent Is Nothing Then
          r = parent.ClientRectangle
          x = r.Width - frm.Width + parent.Left
          y = r.Height - frm.Height + parent.Top
      Else
          r = Screen.PrimaryScreen.WorkingArea
          x = r.Width - frm.Width
          y = r.Height - frm.Height
      End If
  
      x = CInt(x / 2)
      y = CInt(y / 2)
  
      frm.StartPosition = FormStartPosition.Manual
      frm.Location = New Point(x, y)
  End Sub
  </code></pre>
  
  <p>How to get this sub to place form correctly in the middle of the screen or other form if is defined?</p>