confusedbyte
Goto Top

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++
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 );
   }

Content-Key: 342663

Url: https://administrator.de/contentid/342663

Printed on: April 25, 2024 at 11:04 o'clock

Member: MrCount
MrCount Jul 06, 2017 at 12:30:14 (UTC)
Goto Top
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
Member: colinardo
Solution colinardo Jul 06, 2017 updated at 13:06:04 (UTC)
Goto Top
Servus,
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
Grüße Uwe
Member: colinardo
Solution colinardo Jul 23, 2017 at 10:33:05 (UTC)
Goto Top
Wenns das dann war, den Beitrag bitte noch auf gelöst setzen, und Lösungen markieren. Merci.