[SOLUCIONADO] No me deja emparentar el form (Form.parent =)

Iniciado por Eleкtro, 8 Enero 2013, 01:25 AM

0 Miembros y 1 Visitante están viendo este tema.

Eleкtro

En el evento OnMouseHover de un picturebox estoy intentando mostrar un form con la propiedad "CenterParent", pero cuando intento emparentar el form no me deja iniciar la aplicación y me salta error.

Código (vbnet) [Seleccionar]
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Try
           Form2.Parent = Me
       Catch ex As Exception
           MsgBox(ex.Message)
           ' Error: top-level control cannot be added to a control
       End Try
   End Sub








Eleкtro

#1
Ya lo he conseguido, os dejo la solución (Vivan los snippets xD):


Main form:

Código (vbnet) [Seleccionar]
   Private Sub OnMouseHover(sender As Object, e As EventArgs) Handles Button1.MouseHover
       Form2.Show()
   End Sub

   Private Sub OnMouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave
       ' Hay que liberarlo, con un form2.close o form2.hide solo conseguiremos que se centre la primera vez!
       Form2.Dispose()
   End Sub

#Region " CenterForm function "

   Function centerForm(ByVal Form_to_Center As Form, ByVal Form_Location As Point) As Point
       Dim pLocation As New Point
       pLocation.X = (Me.Left + (Me.Width - Form_to_Center.Width) / 2) '// set the X coordinates.
       pLocation.Y = (Me.Top + (Me.Height - Form_to_Center.Height) / 2) '// set the Y coordinates.
       Return pLocation '// return the Location to the Form it was called from.
   End Function

#End Region


Form secundario:
Código (vbnet) [Seleccionar]
   Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Me.Location = Form1.centerForm(Me, Me.Location)
   End Sub