并排显示2个表格

时间:2010-08-11 17:05:07

标签: vb.net winforms

我想并排显示2个表格。 Frm1将调用Frm2。 问题是,如果Frm1太靠近计算机屏幕的边缘,当显示Fr2时,它的一部分将在屏幕外。

如何使它如果Frm1靠近屏幕的右侧,那么Frm2将显示在Frm1的左侧,反之亦然? 感谢

2 个答案:

答案 0 :(得分:1)

假设WinForms,您可以将form.BoundsScreen.FromControl(form).WorkingArea进行比较。

例如:

var screen = Screen.FromControl(form);
if (form.Right < screen.Left + Screen.Width / 2)
    otherForm.Left = screen.Left + Screen.Width / 2;
else
    otherForm.Left = 0;

答案 1 :(得分:0)

终于搞定了,这是解决方案:

 Public Class Form1
    Public IsFormLeft As Boolean
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm1ScreenArea = Screen.FromControl(Me).WorkingArea

        If Me.Right < frm1ScreenArea.Left + frm1ScreenArea.Width / 2 Then
            IsFormLeft = True 'Form1 in Left area
        Else
            IsFormLeft = False 'Form1 in Right area
        End If
        Form2.ShowDialog()
    End Sub
End Class


Public Class Form2
       Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Form1.IsFormLeft Then
            Me.Left = Form1.Left + Form1.Width
            Me.Top = Form1.Top
        Else
            Me.Left = Form1.Right - Form1.Width * 2
            Me.Top = Form1.Top
        End If
    End Sub
End Class