Simple windowed application: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Update for library API changes) |
(Replaced PowerShell with samples with no external dependencies) |
||
Line 1,660: | Line 1,660: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
===Windows Forms=== |
|||
{{libheader|WPK}} |
|||
{{works with|PowerShell|3}} |
|||
<lang powershell>$count = 0 |
|||
<lang PowerShell> |
|||
$Label1 = [System.Windows.Forms.Label]@{ |
|||
Text = 'There have been no clicks yet' |
|||
Size = '200, 20' } |
|||
$Button1 = [System.Windows.Forms.Button]@{ |
|||
Text = 'Click me' |
|||
Location = '0, 20' } |
|||
$Button1.Add_Click( |
|||
{ |
|||
$Script:Clicks++ |
|||
If ( $Clicks -eq 1 ) { $Label1.Text = "There has been 1 click" } |
|||
Else { $Label1.Text = "There have been $Clicks clicks" } |
|||
} ) |
|||
$Form1 = New-Object System.Windows.Forms.Form |
|||
$Form1.Controls.AddRange( @( $Label1, $Button1 ) ) |
|||
$Clicks = 0 |
|||
$Result = $Form1.ShowDialog() |
|||
</lang> |
|||
{{works with|PowerShell|2}} |
|||
<lang PowerShell> |
|||
Add-Type -AssemblyName System.Windows.Forms |
|||
$Label1 = New-Object System.Windows.Forms.Label |
|||
$Label1.Text = 'There have been no clicks yet' |
|||
$Label1.Size = '200, 20' |
|||
$Button1 = New-Object System.Windows.Forms.Button |
|||
$Button1.Text = 'Click me' |
|||
$Button1.Location = '0, 20' |
|||
$Button1.Add_Click( |
|||
{ |
|||
$Script:Clicks++ |
|||
If ( $Clicks -eq 1 ) { $Label1.Text = "There has been 1 click" } |
|||
Else { $Label1.Text = "There have been $Clicks clicks" } |
|||
} ) |
|||
$Form1 = New-Object System.Windows.Forms.Form |
|||
$Form1.Controls.AddRange( @( $Label1, $Button1 ) ) |
|||
$Clicks = 0 |
|||
$Result = $Form1.ShowDialog() |
|||
</lang> |
|||
===WPF=== |
|||
<lang PowerShell> |
|||
[xml]$Xaml = @" |
|||
<Window |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Name = "Window1" |
|||
Width = "200" |
|||
Height = "120" |
|||
ShowInTaskbar = "True"> |
|||
<StackPanel> |
|||
<Label |
|||
x:Name = "Label1" |
|||
Height = "40" |
|||
Width = "200" |
|||
Content = "There have been no clicks"/> |
|||
<Button |
|||
x:Name = "Button1" |
|||
Height = "25" |
|||
Width = "60" |
|||
Content = "Click me"/> |
|||
</StackPanel> |
|||
</Window> |
|||
"@ |
|||
$Window1 = [Windows.Markup.XamlReader]::Load( [System.Xml.XmlNodeReader]$Xaml ) |
|||
$Label1 = $Window1.FindName( "Label1" ) |
|||
$Button1 = $Window1.FindName( "Button1" ) |
|||
$Button1.Add_Click( |
|||
{ |
|||
$Script:Clicks++ |
|||
If ( $Clicks -eq 1 ) { $Label1.Content = "There has been 1 click" } |
|||
Else { $Label1.Content = "There have been $Clicks clicks" } |
|||
} ) |
|||
$Clicks = 0 |
|||
$Result = $Window1.ShowDialog() |
|||
</lang> |
|||
New-Window { |
|||
New-StackPanel { |
|||
New-TextBlock "There have been no clicks yet" ` |
|||
-On_Loaded { |
|||
Set-Variable tb $this |
|||
} |
|||
New-Button "Click me" ` |
|||
-On_Click { |
|||
$count++ |
|||
$tb.Text = $count |
|||
} |
|||
} |
|||
} -SizeToContent WidthAndHeight -Show</lang> |
|||
'''Output''' |
|||
<pre>rexx ShowCount.rxj: |
|||
This Rexx program was invoked by Rexx, JVM loaded by Rexx! |
|||
--- |
|||
win_size (standard): java.awt.Dimension[width=180,height=91] |
|||
but_size (standard): java.awt.Dimension[width=162,height=23] |
|||
win_size (enlarged): java.awt.Dimension[width=270,height=91] |
|||
but_size (enlarged): java.awt.Dimension[width=252,height=23] |
|||
--- </pre> |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
Works with SWI-Prolog and XPCE. |
Works with SWI-Prolog and XPCE. |