PoshCode Archive  Artifact [79d32ee006]

Artifact 79d32ee0066cbe8ea1281692d4afb5742d17a941e1034ddb0784ea0fb773ca97:

  • File Demo-v3-Gui.ps1 — part of check-in [7b9f931fd4] at 2018-06-10 13:32:36 on branch trunk — Very simple, basic script to show how you can utilize v3 syntax to build GUIs with very little code… :) Not useful AT ALL. ;) You can move it around with left mouse button and close with right. :) (user: bielawb size: 2267)

# encoding: ascii
# api: powershell
# title: Demo-v3-Gui.ps1
# description: Very simple, basic script to show how you can utilize v3 syntax to build GUIs with very little code… :) Not useful AT ALL. ;) You can move it around with left mouse button and close with right. :)
# version: 0.5
# author: bielawb
# license: CC0
# x-poshcode-id: 3900
# x-archived: 2013-04-29T03:41:48
# x-published: 2013-01-14T09:16:00
#
#
#requires -version 3

[Windows.Window]@{
    OpacityMask = [Windows.Media.DrawingBrush]@{
        Drawing = [Windows.Media.GeometryDrawing]@{
            Brush = 'Black'
            Geometry = [Windows.Media.EllipseGeometry]@{
                radiusX = 123
                radiusY = 321
            }
        }
    }
    Background = [Windows.Media.LinearGradientBrush]@{
        Opacity = 0.5
        StartPoint = '0,0.5'
        Endpoint = '1,0.5'
        GradientStops = & {
            $Stopki = New-Object Windows.Media.GradientStopCollection
            $Colors = 'Blue', 'Green'
                foreach ($i in 0..1) {
                $Stopki.Add(
                    [Windows.Media.GradientStop]@{
                        Color = $Colors[$i]
                        Offset = $i
                    }
                )
            }
            , $Stopki
        }            
    }
    Width = 800
    Height = 400
    WindowStyle = 'None'
    AllowsTransparency = $true
    Effect = [Windows.Media.Effects.DropShadowEffect]@{
        BlurRadius = 10
    }
    Content = & {
        $Stos = [Windows.Controls.StackPanel]@{
            VerticalAlignment = 'Center'
            HorizontalAlignment = 'Center'
        }

        $Stos.AddChild(
            [Windows.Controls.Label]@{
                Content = 'PowerShell Rocks!'
                FontSize = 80
                FontFamily = 'Consolas'
                Foreground = 'White'
                Effect = [Windows.Media.Effects.DropShadowEffect]@{
                    BlurRadius = 5
                }
            }
        )
        , $Stos
    }
} | foreach {
    $_.Add_MouseLeftButtonDown({
        $this.DragMove()
    })
    $_.Add_MouseRightButtonDown({
        $this.Close()
    })
    $_.ShowDialog()
}