如何在不剪切对话框本身的情况下显示鼠标点对话框?
例如,当我单击屏幕右边缘附近的控件时,对话框将显示在左侧,如果控件位于屏幕下方,则会显示光标对话框。
这是我的代码:
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
即使对话框在窗口外部剪裁,也会始终显示光标右下方的对话框。
答案 0 :(得分:0)
您可以使用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