Error opening form inside panel

4

I'd like to open a form inside a panel, but when it opens, it always stays the same size and in the same place regardless of the size of the form or form.

DimrvAsNewformRVrv.link=lvPasta.SelectedItems(0).ImageKeyrv.FormBorderStyle=FormBorderStyle.Nonerv.Dock=DockStyle.Fillrv.TopLevel=FalseDimpAsNewPanelWithpSize=NewSize(Me.Width,Me.Height)Location=NewPoint(Me.Location.X,Me.Location.Y)EndWithMe.Controls.Add(p)p.BringToFront()p.Controls.Add(rv)p.Show()rv.Show()

Edit:

InadditiontopanelIjusttriedtocreatethenewformanddisplayitbyhidingtheoldform,butIhadtheproblemofthe"blinking" screen while the form swap (main form some - windows chunk - new form appears) and the buttons so that when the new form was closed by "X" (where it normally closes a program) the first form was closed, but when it clicked on another button to "come back" it closed the form2 but not the first form .

Dim rv As New formRodaVideo

        rv.linkvideo = lvPasta.SelectedItems(0).ImageKey
        rv.FormBorderStyle = FormBorderStyle.Sizable
        rv.TopLevel = True
        rv.Width = Me.Width
        rv.Height = Me.Height
        rv.Location = Me.Location
        rv.WindowState = FormWindowState.Normal
        rv.StartPosition = FormStartPosition.WindowsDefaultBounds

        rv.Show()
        Me.Hide()
    
asked by anonymous 14.11.2018 / 21:34

1 answer

0

It looks like the Form is in MdiContainer , where the code below can help you achieve what you want:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim form1 = Me.MdiChildren().Where(Function(r) r.Name = "Form1").FirstOrDefault()

    If Not form1 Is Nothing Then
        form1.Hide()

        Dim form2 As Form1 = New Form1

        AddHandler form2.FormClosed, AddressOf form2_FormClosed

        With form2
            .StartPosition = FormStartPosition.Manual
            .Text = "Form2"
            .MdiParent = form1.MdiParent
            .Size = form1.Size
            .Location = form1.Location
            .Show()
        End With
    End If
End Sub

Private Sub form2_FormClosed(sender As Object, e As FormClosedEventArgs)
    Dim form1 = Me.MdiChildren().Where(Function(r) r.Name = "Form1").FirstOrDefault()
    Dim form2 As Form1 = sender

    If Not form1 Is Nothing Then
        With form1
            .StartPosition = FormStartPosition.Manual
            .BringToFront()
            .Location = form2.Location
            .Size = form2.Size
            .Show()
        End With
    End If
End Sub

You just need to match the names of Form to what you need.

EDIT

If Form is not MdiChild then you can do this (something like the previous one):

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Hide()

        Dim form2 As Form1 = New Form1

        AddHandler form2.FormClosed, AddressOf form2_FormClosed

        With form2
            .StartPosition = FormStartPosition.Manual
            .Text = "Form2"
            .Size = Me.Size
            .Location = Me.Location
            .Show()
        End With
    End Sub

    Private Sub form2_FormClosed(sender As Object, e As FormClosedEventArgs)
        Dim form2 As Form1 = sender

        With Me
            .StartPosition = FormStartPosition.Manual
            .BringToFront()
            .Location = form2.Location
            .Size = form2.Size
            .Show()
        End With
    End Sub
End Class

Assumes the existence of a Button1 button in Form .

That way you no longer have to "blink" between Form , due to the StartPosition = FormStartPosition.Manual property, which prevents you from restarting the location by Show() (I think the location will also be related).

    
15.11.2018 / 19:54