2

code:

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()

with 0 it hits me at the top and if I put (0,0) it hits me on the left as I do so that it hits me on the right at all so I don't have to put (1000,0) the exact horizontal axis? e tested with (-1,0)

1
  • Your words confuse me. Please clarify what you are trying to accomplish and remove terms like "hits me". One thing I can suggest is to use VS and C# to get your form code nailed down.. then move the information over to powershell. Sep 9, 2022 at 15:07

1 Answer 1

2

This will start the window on the far right hand side. The top value can be changed to move it up or down on the side. You do not need $form.Location

In this example, we are essentially setting an (X,Y) value automatically using the total screen width and subtracting it from the form width. Assuming a 1080p monitor is being used (1920x1080) that is 1920 - 350 = 1570. It sets X to 1570 and then Y is the Top value of 0 for a final coordinate window start position (this value is the top left hand corner of the form) of 1570,0. This guarantees the form is snug to the right side of the screen.

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()
1
  • Good answer, but FYI, this line [void]::$monitor.WorkingArea.Width, does not always work in all monitor setups. For example on my main dev box (4 monitors, different sizes), this would throw The property 'Screen[Bounds={X=0,Y=0,Width=1920,Height=1080} WorkingArea={X=0,Y=0,Width=1920,Height=1019} Primary=True DeviceName=\\.\DISPLAY9' cannot be found on this object. Verify that the property exists. It works as expected on my normal client (laptop). So, some additional tweak/expectation is warranted.
    – postanote
    Sep 9, 2022 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .