dennismagno / metroframework-modern-ui

My humble attempt to bring the new Modern UI alias Metro UI of Windows 8 to .NET Windows Forms applications.
http://dennismagno.github.io/metroframework-modern-ui
Other
861 stars 1.08k forks source link

Powershell + MetroFramework Modern UI #56

Open arpsyapathy opened 6 years ago

arpsyapathy commented 6 years ago

Hello. Can i use Metro Framework with Powershell?

I use standard Windows Form like:


Add-Type -assembly System.Windows.Forms
    $main_form = New-Object System.Windows.Forms.Form
    $main_form.Text ='Main menu'
    $main_form.Width = 970
    $main_form.Height = 640
    $main_form.AutoSize = $true

How to use your MetroFramework? Is it possible for Powershell?

techgerm commented 4 years ago

Yes, it's possible.

You'll need to download the MetroFramework DLLs from here and put them somewhere your Powershell script can reference them.

Here's a little sample script I wrote for a testing tool that should help you (or anyone) get started:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -Path "X:/Radar/Test/dlls/MetroFramework.dll"
Add-Type -Path "X:/Radar/Test/dlls/MetroFramework.Design.dll"
Add-Type -Path "X:/Radar/Test/dlls/MetroFramework.Fonts.dll"

$THEME = "Light" # Could use "Dark" instead
$USER_STYLE_COLORS = $false;

# Create main form
$form = New-Object MetroFramework.Forms.MetroForm
$form.Text = "Launch Tests"
$form.AutoSize = $true
$form.Resizable = $false
$form.Theme = $THEME

# Create label
$selectLabel = New-Object MetroFramework.Controls.MetroLabel
$selectLabel.Location = New-Object System.Drawing.Point(20, 65)
$selectLabel.AutoSize = $true
$selectLabel.UseStyleColors = $USER_STYLE_COLORS
$selectLabel.Theme = $THEME
$selectLabel.Text = "Select test(s) to run:"

# Create checkbox
$checkbox = New-Object MetroFramework.Controls.MetroCheckBox
$checkbox.AutoSize = $true;
$checkbox.UseStyleColors = $USER_STYLE_COLORS;
$checkbox.Text = "RDL Unit Tests";
$checkbox.TabIndex = 0;
$checkbox.Location = New-Object System.Drawing.Point(28, 95);
$checkbox.Theme = $THEME

# Create launch button 
$launchButton = New-Object MetroFramework.Controls.MetroButton
$launchButton.Left = ($form.Width - $launchButton.Width) / 2
$launchButton.Top = $form.Height - $launchButton.Height
$launchButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$launchButton.AutoSize = $true
$launchButton.Highlight = $true
$launchButton.Text = "Launch"
$launchButton.Theme = $THEME
$launchButton.TabIndex = 1

# Configure form controls
$form.AcceptButton = $launchButton
$form.Controls.AddRange(@(
        $selectLabel,
        $launchButton,
        $checkbox
    ))

# Launch Form
$result = $form.ShowDialog()
If ($result -eq [System.Windows.Forms.DialogResult]::OK) {
    Write-Host "Do something with user input..." -ForegroundColor "Green"
}
Else {
    Write-Host "Application closed" -ForegroundColor "Red"
}

I also highly recommend referencing the MetroFramework demo application designer file as it will show you essentially how to implement the rest of the components displayed in the demo screenshots from here.