在不裁剪窗体外部的情况下显示对话框
Show Dialog without clipping outside a form
如何在鼠标点上显示对话框而不将对话框本身剪裁到外面?
例如,当我右击屏幕右边缘附近的控件时,对话框将出现在左侧,如果控件靠近屏幕下方,它将显示对话框的上方光标。
这是我的代码:
If e.Button = MouseButtons.Right Then
Dim tool = New Form2 With {
.Location = New Point(Cursor.Position.X, Cursor.Position.Y),
.WhoSend = sender 'some property
}
tool.ShowDialog()
End If
这将始终在光标的右下角显示对话框,即使对话框在 window 之外剪裁也是如此。
您可以使用My.Computer.Screen.Bounds
获取屏幕的区域并根据它设置位置,然后重新定位您的表格位置。
If e.Button = MouseButtons.Right Then
Dim ScreenBounds = My.Computer.Screen.Bounds
Dim tool = New Form2 With {
.Location = New Point(if( Cursor.Position.X + .Width > ScreenBounds.Width,ScreenBounds.Width - .Width ,Cursor.Position.X ),
if( Cursor.Position.Y + .Height > ScreenBounds.Width,ScreenBounds.Height - .Height ,Cursor.Position.Y ),
.WhoSend = sender 'some property
}
tool.ShowDialog()
End If
如何在鼠标点上显示对话框而不将对话框本身剪裁到外面?
例如,当我右击屏幕右边缘附近的控件时,对话框将出现在左侧,如果控件靠近屏幕下方,它将显示对话框的上方光标。
这是我的代码:
If e.Button = MouseButtons.Right Then
Dim tool = New Form2 With {
.Location = New Point(Cursor.Position.X, Cursor.Position.Y),
.WhoSend = sender 'some property
}
tool.ShowDialog()
End If
这将始终在光标的右下角显示对话框,即使对话框在 window 之外剪裁也是如此。
您可以使用My.Computer.Screen.Bounds
获取屏幕的区域并根据它设置位置,然后重新定位您的表格位置。
If e.Button = MouseButtons.Right Then
Dim ScreenBounds = My.Computer.Screen.Bounds
Dim tool = New Form2 With {
.Location = New Point(if( Cursor.Position.X + .Width > ScreenBounds.Width,ScreenBounds.Width - .Width ,Cursor.Position.X ),
if( Cursor.Position.Y + .Height > ScreenBounds.Width,ScreenBounds.Height - .Height ,Cursor.Position.Y ),
.WhoSend = sender 'some property
}
tool.ShowDialog()
End If