将表单定位到最右侧 Windows.Forms

将表单定位到最右侧 Windows.Forms

代码:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()

$form = New-Object System.Windows.Forms.Form
$form.Text = 'Busca Email'
$form.ClientSize = ‘350,180’
$form.StartPosition = "manual"
$form.Location = New-Object System.Drawing.Point(1000,0)
$form.AutoSize = $true

$form.ShowDialog()

如果是 0,它会打到顶部;如果我放 (0,0),它会打到左边,这样它就完全打到右边了,所以我不必把 (1000,0) 放进精确的水平轴?用 (-1,0) 测试

答案1

这将启动最右侧的窗口。top可以更改该值以将其向上或向下移动到侧面。您不需要$form.Location

在此示例中,我们基本上是使用总屏幕宽度自动设置 (X,Y) 值,并将其从表单宽度中减去。假设使用的是 1080p 显示器 (1920x1080),即 1920 - 350 = 1570。它设置X1570,然后Y将是最终坐标窗口起始位置 (此值是表单的左上角) 的值Top。这可确保表单紧贴屏幕右侧。01570,0

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$monitor = [System.Windows.Forms.Screen]::PrimaryScreen

[void]::$monitor.WorkingArea.Width

$form = New-Object System.Windows.Forms.Form
$form.Text = 'Busca Email'
$form.ClientSize = ‘350,180’
$form.StartPosition = "manual"
$form.Left = $monitor.WorkingArea.Width - $form.Width
$form.Top = 0
#$form.Location = New-Object System.Drawing.Point(1000,0)
$form.AutoSize = $true


$form.ShowDialog()

相关内容