我正在处理包含两个窗体的应用程序:
如果用户将第一个表单的大小更改为包含所有桌面的最大大小,我希望如此。加载时的下一个表单,它的大小会更改为最大值。
我写了这个,但没有奏效:
Private Sub sc(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
If Me.Size = New Size(MaximumSize) Then
MainMenu.Size = New Size(MaximumSize)
End If
End Sub
如果你能帮助我,我会很高兴。
答案 0 :(得分:1)
在显示之前,将新表单的WindowState
设置为当前表单的WindowState
。
此外,如果表单未最大化,如果您想要显示下一个表单与第一个表单的大小和位置完全相同,您还可以设置新表单的Size
和Location
:
'I suppose this is the button on the first form that opens the second form
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'I Suppose Form2 is your new Form
Dim f As New Form2()
f.WindowState = Me.WindowState
f.Location = Me.Location
f.Size = Me.Size
f.StartPosition = FormStartPosition.Manual
f.ShowDialog()
End Sub
答案 1 :(得分:0)
我把这段代码放在form2_load部分并且工作
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Maximize form size if the past form size is maximized
If Form1.WindowState = FormWindowState.Maximized Then
Me.WindowState = FormWindowState.Maximized
End If