Have form in right bottom corner?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Have form in right bottom corner?

Post by jvierra »

Here is a Microsoft example that is the first example that comes up when using a search engine with a good questiuon:

"winforms set form location"

You can use that question to get more examples.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Have form in right bottom corner?

Post by jvierra »

Here is a simple question that will get numerous examples of how to set the screen location of a form:

https://social.technet.microsoft.com/Fo ... powershell

Just add "powershell" to the beginning of the previous search question to get PowerShell answer first.

Like this: "powershell winforms set form location"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Have form in right bottom corner?

Post by jvierra »

Here, I threw this together quickly. It should work.
  1. $form1_Load = {
  2.    
  3.     $x = [system.windows.forms.screen]::PrimaryScreen.Bounds.Width - $form1.Bounds.Width
  4.     $y = [system.windows.forms.screen]::PrimaryScreen.Bounds.Height - $form1.Bounds.Height
  5.     $form1.Location = [System.drawing.point]::New($x, $y)
  6.    
  7. }
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Have form in right bottom corner?

Post by stevens »

Almost there. Found this and this code works

$monitor = [System.Windows.Forms.Screen]::PrimaryScreen

$widthFactor = 0.77
#$heightFactor = 0.0333333333333333
$heightFactor = 0.62

$formChatBot.Location = New-Object System.Drawing.Point(($monitor.WorkingArea.Width * $widthFactor), ($monitor.WorkingArea.Height * $heightFactor))
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Have form in right bottom corner?

Post by stevens »

Almost there. Found this and this: viewtopic.php?t=15365
The code works

$monitor = [System.Windows.Forms.Screen]::PrimaryScreen

$widthFactor = 0.77
#$heightFactor = 0.0333333333333333
$heightFactor = 0.62

$MyForm.Location = New-Object System.Drawing.Point(($monitor.WorkingArea.Width * $widthFactor), ($monitor.WorkingArea.Height * $heightFactor))

On a smaller screen it is in the right bottom corner, still visible (the form), but only half of it. If I change the widthfactor it doesn't seem to do much.
Any suggestions?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Have form in right bottom corner?

Post by stevens »

Thanks. Works fine now, only thing is that I did have to add -20

$x = [system.windows.forms.screen]::PrimaryScreen.Bounds.Width - $formChatBot.Bounds.Width
$y = [system.windows.forms.screen]::PrimaryScreen.Bounds.Height - $formChatBot.Bounds.Height
$formChatBot.Location = [System.drawing.point]::New($x, $y - 50)


The form: viewtopic.php?t=15842
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked