
02.03.2010, 01:29
|
|
Познавший АНТИЧАТ
Регистрация: 12.07.2008
Сообщений: 1,705
С нами:
9384806
Репутация:
1350
|
|
Для создания базовых элементов Windows Form на Powershell,есть замечательная программа от Sapien под названием PrimalForms( http://www.primaltools.com/downloads/communitytools/download.asp?file=pforms ) . С помощью нее можно быстро создать базовые элементы,так же можно использовать Visual Studio( здесь будет сложнее,код создается на C# ,в программе выше сразу имеем код на PowerShell).Так же другие полезные программы от Sapien для PowerShell на сайте http://www.primaltools.com/downloads/communitytools/index.asp
PrimalForms Community Edition is a free GUI builder tool for PowerShell users. It edits and stores Windows Forms in a native XML format and generates PowerShell code on demand. Sample forms included.
И сделал с помощью PrimalForms простой пример с удалением дублей без учета регистра.Просто небольшой показ возможностей.
Наша форма:
Ничего сверхестественного скрипт не делает,а лишь выполняет команду:
Get-Content "$filename" | Select-Object -Unique | Out-File "$savename"
Сам скрипт:
#Generated Form Function
function GenerateForm {
################################################## ######################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition)
# Generated On: 02.03.2010
# Generated By: SpangeBoB
################################################## ######################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button4 = New-Object System.Windows.Forms.Button
$button3 = New-Object System.Windows.Forms.Button
$richTextBox2 = New-Object System.Windows.Forms.RichTextBox
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$button2 = New-Object System.Windows.Forms.Button
$button1 = New-Object System.Windows.Forms.Button
$openFileDialog1 = New-Object System.Windows.Forms.OpenFileDialog
$saveFileDialog1 = New-Object System.Windows.Forms.SaveFileDialog
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button3_OnClick=
{
#TODO: Place custom script here
$form1.close()
}
$button1_OnClick=
{
#TODO: Place custom script here
$openFileDialog1.InitialDirectory = "C:\"
$openFileDialog1.Filter = "All files (*.*)| *.*"
$openFileDialog1.FilterIndex = 2
$openFileDialog1.RestoreDirectory = $true
if($openFileDialog1.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK)
{
try
{
if (($filename=$openFileDialog1.OpenFile().Name) -ne $null)
{
$richTextBox1.Text=$filename
}
}
catch
{
[System.Windows.Forms.MessageBox]::Show("Error: Could not read file from disk. Original error: " + $error[0].Exception.Message)
}
}
}
$handler_openFileDialog1_FileOk=
{
#TODO: Place custom script here
}
$handler_saveFileDialog1_FileOk=
{
#TODO: Place custom script here
}
$button2_OnClick=
{
#TODO: Place custom script here
$saveFileDialog1.InitialDirectory = "C:\"
$saveFileDialog1.Filter = "All files (*.*)| *.*"
$saveFileDialog1.FilterIndex = 2
$saveFileDialog1.RestoreDirectory = $true
if($saveFileDialog1.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK)
{
try
{
if (($savename=$saveFileDialog1.OpenFile().Name) -ne $null)
{
$richTextBox2.Text=$savename
}
}
catch
{
[System.Windows.Forms.MessageBox]::Show("Error: Could not save file from disk. Original error: " + $error[0].Exception.Message)
}
}
}
$handler_form1_Load=
{
#TODO: Place custom script here
}
$button4_OnClick=
{
Write-Host $filename
Write-Host $savename
$saveFileDialog1.Reset()
Get-Content "$filename" | Select-Object -Unique | Out-File "$savename"
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = 'Get Uniq'
$form1.Name = 'form1'
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 456
$System_Drawing_Size.Height = 205
$form1.ClientSize = $System_Drawing_Size
$form1.add_Load($handler_form1_Load)
$button4.TabIndex = 7
$button4.Name = 'button4'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 87
$System_Drawing_Size.Height = 25
$button4.Size = $System_Drawing_Size
$button4.UseVisualStyleBackColor = $True
$button4.Text = 'Run'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 323
$System_Drawing_Point.Y = 168
$button4.Location = $System_Drawing_Point
$button4.DataBindings.DefaultDataSourceUpdateMode = 0
$button4.add_Click($button4_OnClick)
$form1.Controls.Add($button4)
$button3.TabIndex = 6
$button3.Name = 'button3'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 87
$System_Drawing_Size.Height = 25
$button3.Size = $System_Drawing_Size
$button3.UseVisualStyleBackColor = $True
$button3.Text = 'Exit'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 30
$System_Drawing_Point.Y = 168
$button3.Location = $System_Drawing_Point
$button3.DataBindings.DefaultDataSourceUpdateMode = 0
$button3.add_Click($button3_OnClick)
$form1.Controls.Add($button3)
$richTextBox2.Name = 'richTextBox2'
$richTextBox2.Text = ''
$richTextBox2.DataBindings.DefaultDataSourceUpdate Mode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 38
$System_Drawing_Point.Y = 109
$richTextBox2.Location = $System_Drawing_Point
$richTextBox2.Multiline = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 279
$System_Drawing_Size.Height = 21
$richTextBox2.Size = $System_Drawing_Size
$richTextBox2.TabIndex = 5
$form1.Controls.Add($richTextBox2)
$richTextBox1.Name = 'richTextBox1'
$richTextBox1.Text = ''
$richTextBox1.DataBindings.DefaultDataSourceUpdate Mode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 38
$System_Drawing_Point.Y = 48
$richTextBox1.Location = $System_Drawing_Point
$richTextBox1.Multiline = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 279
$System_Drawing_Size.Height = 21
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 4
$form1.Controls.Add($richTextBox1)
$button2.TabIndex = 3
$button2.Name = 'button2'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 99
$System_Drawing_Size.Height = 21
$button2.Size = $System_Drawing_Size
$button2.UseVisualStyleBackColor = $True
$button2.Text = 'Save'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 323
$System_Drawing_Point.Y = 109
$button2.Location = $System_Drawing_Point
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$button2.add_Click($button2_OnClick)
$form1.Controls.Add($button2)
$button1.TabIndex = 1
$button1.Name = 'button1'
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 99
$System_Drawing_Size.Height = 21
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = 'Open'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 323
$System_Drawing_Point.Y = 48
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$openFileDialog1.ShowHelp = $True
$openFileDialog1.FileName = 'file'
$openFileDialog1.add_FileOk($handler_openFileDialo g1_FileOk)
$saveFileDialog1.ShowHelp = $True
$saveFileDialog1.FileName = 'file'
$saveFileDialog1.add_FileOk($handler_saveFileDialo g1_FileOk)
#endregion Generated Form Code
#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
|
|
|