Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check for config csv file and create it if needed
- $ConfigFile = ".\PasterTool.config"
- If(!(Test-Path $ConfigFile)){ "ButtonText,ButtonValue" > $ConfigFile}
- Function GenerateButton {
- [CmdletBinding()]
- Param(
- [parameter(Mandatory=$true)]
- [String]$Text,
- [parameter(Mandatory=$true)]
- [String]$Value,
- [parameter(Mandatory=$true)]
- [String]$LineNumber
- )
- $Button = New-Object System.Windows.Forms.Button
- $Button.Text = $Text
- $Button.TabIndex = $LineNumber-1
- $Button.Name = “$Text”
- $Button.Size = New-Object System.Drawing.Size(240,23)
- $Button.UseVisualStyleBackColor = $True
- $Button.Location = New-Object System.Drawing.Point(13,(-20+30*$LineNumber))
- $Button.DataBindings.DefaultDataSourceUpdateMode = 0
- $Button.add_Click({$Value | clip.exe})
- Return $Button
- }
- Function GenerateForm {
- # Form Variables
- #==========================
- [reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
- [reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
- $Form = New-Object System.Windows.Forms.Form
- $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
- $OnLoadForm_StateCorrection= {$Form.WindowState = $InitialFormWindowState}
- $Form.Text = “Paster Tool”
- $Form.Name = “Form”
- $Form.Topmost = $True
- $Form.DataBindings.DefaultDataSourceUpdateMode = 0
- $FormDrawingSize = New-Object System.Drawing.Size(265,275)
- $Form.ClientSize = $FormDrawingSize
- # Generate Buttons on Form
- #==========================
- $Config = Import-CSV $ConfigFile
- $LineNumber = 1
- Foreach($Line in $Config){
- $Form.Controls.Add((GenerateButton -Text $Line.ButtonText -Value $Line.ButtonValue -LineNumber $LineNumber))
- $LineNumber++
- }
- # Load Form
- #==========================
- $InitialFormWindowState = $Form.WindowState
- $Form.add_Load($OnLoadForm_StateCorrection)
- $Form.ShowDialog()| Out-Null
- }
- GenerateForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement