I designed two forms in VB
. The main form sets the height and width of the 2nd form and opens it with .ShowDialog(), everything is fine.
Now I need to open the 2nd form non-modal with .Show(), but some things don't work now:
- The height and width properties of the 2nd form cannot be get or set in the main form. I set all properties after loading the main and get them before closing the main.
- When I change the form size, close the form and open it again, the size always goes back to default.
- The main form stays always in background. It's not possible to bring it to front. The 2nd form always hovers above.
Any ideas?
I use .NET 4.5
and Visual Studio 2019
.
Here's some code:
Public Class FormMain
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadWindowPos()
End Sub
Private Sub FormMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
SaveWindowPos()
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Form2.Show()
End Sub
End Class
Module ModuleGlobal
Public Sub LoadWindowPos()
'Get integers from file
Form2.Height = 100
Form2.Width = 200
End Sub
Public Sub SaveWindowPos()
Dim sLine as String = Form2.Height.ToString & ";" & Form2.Width.ToString
System.IO.File.WriteAllLines("filename.ini", sLine, System.Text.Encoding.Default)
End Sub
End Module