Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # Check for config csv file and create it if needed
  3. $ConfigFile = ".\PasterTool.config"
  4. If(!(Test-Path $ConfigFile)){ "ButtonText,ButtonValue" > $ConfigFile}
  5.  
  6.  
  7.  
  8. Function GenerateButton {
  9.    
  10.     [CmdletBinding()]
  11.     Param(
  12.         [parameter(Mandatory=$true)]
  13.         [String]$Text,
  14.        
  15.         [parameter(Mandatory=$true)]
  16.         [String]$Value,
  17.        
  18.         [parameter(Mandatory=$true)]
  19.         [String]$LineNumber    
  20.     )
  21.  
  22.     $Button = New-Object System.Windows.Forms.Button
  23.     $Button.Text = $Text
  24.     $Button.TabIndex = $LineNumber-1
  25.     $Button.Name =$Text
  26.     $Button.Size = New-Object System.Drawing.Size(240,23)
  27.     $Button.UseVisualStyleBackColor = $True
  28.     $Button.Location = New-Object System.Drawing.Point(13,(-20+30*$LineNumber))
  29.     $Button.DataBindings.DefaultDataSourceUpdateMode = 0
  30.     $Button.add_Click({$Value | clip.exe})
  31.  
  32.     Return $Button
  33. }
  34.  
  35.  
  36.  
  37.  
  38. Function GenerateForm {
  39.  
  40.     # Form Variables
  41.     #==========================
  42.     [reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
  43.     [reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
  44.  
  45.     $Form = New-Object System.Windows.Forms.Form
  46.     $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  47.     $OnLoadForm_StateCorrection= {$Form.WindowState = $InitialFormWindowState}
  48.  
  49.     $Form.Text = “Paster Tool”
  50.     $Form.Name = “Form”
  51.     $Form.Topmost = $True
  52.     $Form.DataBindings.DefaultDataSourceUpdateMode = 0
  53.     $FormDrawingSize = New-Object System.Drawing.Size(265,275)
  54.     $Form.ClientSize = $FormDrawingSize
  55.    
  56.    
  57.    
  58.     # Generate Buttons on Form
  59.     #==========================
  60.     $Config = Import-CSV $ConfigFile
  61.     $LineNumber = 1
  62.     Foreach($Line in $Config){
  63.         $Form.Controls.Add((GenerateButton -Text $Line.ButtonText -Value $Line.ButtonValue -LineNumber $LineNumber))
  64.         $LineNumber++
  65.      }
  66.  
  67.  
  68.    
  69.     # Load Form
  70.     #==========================
  71.     $InitialFormWindowState = $Form.WindowState
  72.     $Form.add_Load($OnLoadForm_StateCorrection)
  73.     $Form.ShowDialog()| Out-Null
  74.  
  75. }
  76.  
  77.  
  78. GenerateForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement