Windows Forms mit Powershell rechts unten in die Ecke des Bildschirm setzen?
Hey alle zusammen,
ich habe ein kleines Problem:
ich habe eine Anwendung geschrieben die den User informieren soll (mit Powershell WindowsForms), nun sind Hardware bedingt verschiedene Auflösungen im Unternehmen vorhanden.
Die Anwendung soll rechts unten in die Ecke.
Ich könnte jetzt eine Solutionsabfrage machen und danach das ganze ausrichten.
Geht es aber nicht auch einfacher?
in C# oder c++ kann ich meines Wissens, Screen.PrimaryScreen.WorkingArea verwenden, geht das nicht auch in PS.
manchmal sieht man den Wald vor lauter Bäumen nicht.
Bsp. in c++
ich habe ein kleines Problem:
ich habe eine Anwendung geschrieben die den User informieren soll (mit Powershell WindowsForms), nun sind Hardware bedingt verschiedene Auflösungen im Unternehmen vorhanden.
Die Anwendung soll rechts unten in die Ecke.
Ich könnte jetzt eine Solutionsabfrage machen und danach das ganze ausrichten.
Geht es aber nicht auch einfacher?
in C# oder c++ kann ich meines Wissens, Screen.PrimaryScreen.WorkingArea verwenden, geht das nicht auch in PS.
manchmal sieht man den Wald vor lauter Bäumen nicht.
Bsp. in c++
private:
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
System::Drawing::Rectangle workingRectangle = Screen::PrimaryScreen->WorkingArea;
this->Size = System::Drawing::Size( workingRectangle.Width - 10, workingRectangle.Height - 10 );
this->Location = System::Drawing::Point( 5, 5 );
}
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 342663
Url: https://administrator.de/forum/windows-forms-mit-powershell-rechts-unten-in-die-ecke-des-bildschirm-setzen-342663.html
Ausgedruckt am: 12.05.2025 um 17:05 Uhr
3 Kommentare
Neuester Kommentar
Servus,
welche dieser Seiten hast du denn schon nach einer Lösung durchstöbert?
https://www.google.de/?gws_rd=ssl#q=powershell+windows+forms+position
welche dieser Seiten hast du denn schon nach einer Lösung durchstöbert?
https://www.google.de/?gws_rd=ssl#q=powershell+windows+forms+position
Servus,
bidde:
Grüße Uwe
bidde:
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
$form1 = New-Object System.Windows.Forms.Form
$btnBottomRight = New-Object System.Windows.Forms.Button
$btnBottomLeft = New-Object System.Windows.Forms.Button
$btnTopRight = New-Object System.Windows.Forms.Button
$btnTopLeft = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$screenwidth = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width
$screenheight = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height
$handler_btnTopRight_Click=
{
$form1.Top = 0
$form1.Left = $screenwidth - $form1.Width
}
$handler_btnBottomRight_Click=
{
$form1.Top = $screenheight - $form1.Height
$form1.Left = $screenwidth - $form1.Width
}
$handler_form1_Load={}
$handler_btnBottomLeft_Click=
{
$form1.Top = $screenheight - $form1.Height
$form1.Left =0
}
$handler_btnTopLeft_Click=
{
$form1.Top = 0
$form1.Left = 0
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 130
$System_Drawing_Size.Width = 361
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Demo-Form"
$form1.add_Load($handler_form1_Load)
$btnBottomRight.Anchor = 10
$btnBottomRight.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 274
$System_Drawing_Point.Y = 95
$btnBottomRight.Location = $System_Drawing_Point
$btnBottomRight.Name = "btnBottomRight"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$btnBottomRight.Size = $System_Drawing_Size
$btnBottomRight.TabIndex = 3
$btnBottomRight.Text = "Bottom Right"
$btnBottomRight.UseVisualStyleBackColor = $True
$btnBottomRight.add_Click($handler_btnBottomRight_Click)
$form1.Controls.Add($btnBottomRight)
$btnBottomLeft.Anchor = 6
$btnBottomLeft.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 95
$btnBottomLeft.Location = $System_Drawing_Point
$btnBottomLeft.Name = "btnBottomLeft"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 83
$btnBottomLeft.Size = $System_Drawing_Size
$btnBottomLeft.TabIndex = 2
$btnBottomLeft.Text = "Bottom Left"
$btnBottomLeft.UseVisualStyleBackColor = $True
$btnBottomLeft.add_Click($handler_btnBottomLeft_Click)
$form1.Controls.Add($btnBottomLeft)
$btnTopRight.Anchor = 9
$btnTopRight.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 274
$System_Drawing_Point.Y = 12
$btnTopRight.Location = $System_Drawing_Point
$btnTopRight.Name = "btnTopRight"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$btnTopRight.Size = $System_Drawing_Size
$btnTopRight.TabIndex = 1
$btnTopRight.Text = "Top Right"
$btnTopRight.UseVisualStyleBackColor = $True
$btnTopRight.add_Click($handler_btnTopRight_Click)
$form1.Controls.Add($btnTopRight)
$btnTopLeft.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$btnTopLeft.Location = $System_Drawing_Point
$btnTopLeft.Name = "btnTopLeft"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 83
$btnTopLeft.Size = $System_Drawing_Size
$btnTopLeft.TabIndex = 0
$btnTopLeft.Text = "Top Left"
$btnTopLeft.UseVisualStyleBackColor = $True
$btnTopLeft.add_Click($handler_btnTopLeft_Click)
$form1.Controls.Add($btnTopLeft)
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
Wenns das dann war, den Beitrag bitte noch auf gelöst setzen, und Lösungen markieren. Merci.