我会处理Form.Paint
事件的形式和调整/计算你的控件的大小和位置。这不是最干净或最简单的解决方案,所以如果可以的话,您应该尝试让内置布局控件中的一个工作。
Private Sub MyForm_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Try
'get height of title
Dim titleHeight As Integer = RectangleToScreen(parent.ClientRectangle).Top - parent.Top
'set paddingTop to height of title + height of menustrip(if you have one) + 10px(can be whatever you want) padding
Dim paddingTop As Integer = titleHeight + parent.MenuStrip1.Height + 10
REM Adjust controls sized to scale based on new form size
PictureBox1.Size = New Size(CInt(Width/4), CInt(Height/2))
PictureBox1.Location = New Point(CInt(Width/4 + PictureBox1.Width/2), paddingTop)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
显然,你需要知道你的控件相对于父窗体的规模和位置,所以如果形式的纵横比改变你的布局不会瓦解。您还应该考虑为父表单设置最小尺寸以避免此类问题。您还可以处理Form.SizeChanged
以减少代码运行的次数,但我遇到了不足的情况。
你在说C#/ Winforms吗?你的问题有点不清楚,并没有显示任何代码。 –
对于比花生更复杂的任何东西,您可能需要合并[TableLayoutPanel](https://msdn.microsoft.com/en-us/library/h21wykkx(v = vs.110).aspx)容器。 –
@Ransom你想看什么代码? – Sam