[英]Powershell- Function call is not working in the add_click method. Please advice
I am trying to call function OKButtonEvent inside the on click event but whenever I am clicking on OK button nothing happens.我试图在点击事件中调用 function OKButtonEvent 但每当我点击确定按钮时都没有任何反应。 I have created checkboxes and on selected checkboxes, I am calling different-different powershell scripts but seems not working.
我已经创建了复选框,并且在选定的复选框上,我正在调用不同的 powershell 脚本,但似乎不起作用。 I have tried different -2 things but nothing works.
我尝试了不同的 -2 东西,但没有任何效果。 One question if I do select 3 checkboxes then during the on click event of OK button all conditions based on 3 selected checkboxes will execute?
一个问题,如果我做 select 3 个复选框,那么在 OK 按钮的单击事件期间,所有基于 3 个选定复选框的条件都会执行?
Below is my script:下面是我的脚本:
function Test-AnyButtonChecked
{
if ($checkbox1.Checked -or $checkbox2.Checked -or $checkbox3.Checked -or $checkbox4.Checked)
{
$OKButton.Enabled = $true
}
else
{
$OKButton.Enabled = $false
}
}
function OKButtonEvent
{
if ($checkbox1.Checked)
{
echo "hi CB1"
& ((Split-Path $MyInvocation.InvocationName)+"\abc.ps1")
}
if ($checkbox2.Checked)
{
write-host "hi CB2"
& ((Split-Path $MyInvocation.InvocationName)+"\bcd.ps1")
}
if ($checkbox3.Checked)
{
& ((Split-Path $MyInvocation.InvocationName)+"\cde.ps1")
}
if ($checkbox4.Checked)
{
& ((Split-Path $MyInvocation.InvocationName)+"\def.ps1")
}
}
function checkbox_test
{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# Set the size of your form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 1000
$Form.height = 700
$Form.Text = ”ABC Scan”
# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font("Times New Roman",12)
$Form.Font = $Font
# create your checkbox
$checkbox1 = new-object System.Windows.Forms.checkbox
$checkbox1.Location = new-object System.Drawing.Size(60,30)
$checkbox1.Size = new-object System.Drawing.Size(250,50)
$checkbox1.Text = "OS Scan"
$checkbox1.Checked = $true
$Form.Controls.Add($checkbox1)
# create your checkbox
$checkbox2 = new-object System.Windows.Forms.checkbox
$checkbox2.Location = new-object System.Drawing.Size(60,90)
$checkbox2.Size = new-object System.Drawing.Size(250,50)
$checkbox2.Text = "ARP Scan - Publisher"
$checkbox2.Checked = $true
$Form.Controls.Add($checkbox2)
# create your checkbox
$checkbox3 = new-object System.Windows.Forms.checkbox
$checkbox3.Location = new-object System.Drawing.Size(60,150)
$checkbox3.Size = new-object System.Drawing.Size(350,50)
$checkbox3.Text = "ARP Scan - Display Name"
$checkbox3.Checked = $true
$Form.Controls.Add($checkbox3)
# create your checkbox
$checkbox4 = new-object System.Windows.Forms.checkbox
$checkbox4.Location = new-object System.Drawing.Size(60,210)
$checkbox4.Size = new-object System.Drawing.Size(250,50)
$checkbox4.Text = "File Scan GCI"
$checkbox4.Checked = $true
$Form.Controls.Add($checkbox4)
# Add an OK button
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = new-object System.Drawing.Size(400,550)
$OKButton.Size = new-object System.Drawing.Size(100,40)
$OKButton.Text = "OK"
$OKButton.add_Click({$button_click_1})
$form.Controls.Add($OKButton)
#$form.AcceptButton = $OKButton
#Add a cancel button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = new-object System.Drawing.Size(600,550)
$CancelButton.Size = new-object System.Drawing.Size(100,40)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$Form.Close()})
$form.Controls.Add($CancelButton)
########### This is the important piece ##############
# #
# Do something when the state of the checkbox changes #
#######################################################
$checkbox1.add_CheckedChanged( { Test-AnyButtonChecked })
$checkbox2.add_CheckedChanged( { Test-AnyButtonChecked })
$checkbox3.add_CheckedChanged( { Test-AnyButtonChecked })
$checkbox4.add_CheckedChanged( { Test-AnyButtonChecked })
$button_click_1={OKButtonEvent}
# Activate the form
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
}
#Call the function
checkbox_test
So I made this app for a scanner at work.所以我为工作中的扫描仪制作了这个应用程序。 It reads barcodes and makes a list of them.
它读取条形码并列出它们。 And then when you want the labels printed out for the codes you paste the code into a html page with the input box.
然后,当您想要打印代码的标签时,您可以将代码粘贴到带有输入框的 html 页面中。 (At least I do...) This app helps us out by doing that automatically, so I don't have to walk around the kitchen making single scans.
(至少我这样做......)这个应用程序通过自动执行此操作来帮助我们,所以我不必在厨房里走来走去进行单次扫描。 I just scan them all at once into my textbox and hit print and aim.
我只是一次将它们全部扫描到我的文本框中,然后点击打印和瞄准。
Try it... put some numbers or words or letters in there seperated by tabs like a scanner would automatically put.试试看……在里面放一些数字、单词或字母,用标签隔开,就像扫描仪会自动放的一样。 Then hit fix list.
然后点击修复列表。
...its kind of wild but I know it should help you make your functions work with the controls. ...有点狂野,但我知道它应该可以帮助您使您的功能与控件一起使用。 It's a good class example.
这是一个很好的 class 示例。
Oh by the way.. create a folder in your documents folder called testOneX first... and save your work too before trying.哦顺便说一句..首先在您的文档文件夹中创建一个名为 testOneX 的文件夹...并在尝试之前保存您的工作。
#You might need to set your execution policies for -scope currentUser
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
class autoListVars
{
[int]$MbuttonSizeXY = 100
[int]$RbuttonSizeX
[int]$RbuttonSizeY
[int]$RbuttonGapX
[int]$RbuttonGapY
[int]$textBoxSizeX
[int]$textBoxSizeY
[int]$formSizeX
[int]$formSizeY
[int]$disBoxSizeX
[int]$disBoxSizeY
[string]$someText
[string]$genPath
[int]$MPointX
[int]$MPointY
[int]$labDrop = 30
[int]$lab1X
[int]$lab1Y
[int]$lab2X
[int]$lab2Y
[int]$lab3X
[int]$lab3Y
[object]$formP
[object]$topLabel1
[object]$topLabel2
[object]$topLabel3
[object]$textBoxP
[object]$displayBox1
[object]$mainMacroButton
[object]$canButton
[object]$autoButton
[object]$curButton
[object]$fxlButton
[object]$clrButton
[object]$backButton
[int]$formPX
[int]$topLabel1X
[int]$topLabel2X
[int]$topLabel3X
[int]$textBoxPX
[int]$displayBoxX
[int]$mainMacroButtonX
[int]$canButtonX
[int]$autoButtonX
[int]$curButtonX
[int]$fxlButtonX
[int]$clrButtonX
[int]$backButtonX
[int]$formPY
[int]$topLabel1Y
[int]$topLabel2Y
[int]$topLabel3Y
[int]$textBoxPY
[int]$displayBoxY
[int]$mainMacroButtonY
[int]$canButtonY
[int]$autoButtonY
[int]$curButtonY
[int]$fxlButtonY
[int]$clrButtonY
[int]$backButtonY
[string]$profile = $profile
[string]$fileArea
[string]$placeName
[string]$cacName
[string]$newTextDone
[string]$newText
[string]$backText
[string]$backTextDone
}
class autoPrintForm : autoListVars
{
autoPrintForm()
{
$this.formMetrics()
$this.startForm()
$this.topLabel1.text = $this.fileArea
$this.shower()
}
autoPrintForm([int]$formSizeBase)
{
$this.MbuttonSizeXY = $formSizeBase
$this.formMetrics()
$this.startForm()
$this.topLabel1.text = $this.cacName
#$this.displayBox1.Text = $this.fileArea
$this.shower()
}
[void]formMainDir()
{
$nameOfPlace = "\testOneX"
$this.placeName = $nameOfPlace
$nameOfStop = "Documents"
$fileBins = $nameOfStop
$fileBinsL = $fileBins.Length
$startLFileName = $this.profile.IndexOf($nameOfStop)
$mainArea = $this.profile.Substring(0, $startLFileName + $fileBinsL)
$proof = $mainArea
$this.fileArea = $mainArea
$this.cacName = $this.fileArea + $this.placeName
$this.newTextDone = $this.cacName + "\newListZX.txt"
$this.newText = $this.cacName + "\newList.txt"
$this.backText = $this.cacName + "\backText.txt"
$this.backTextDone = $this.cacName + "\backTextDone.txt"
}
[void]formMetrics()
{
$this.formMainDir()
$this.RbuttonSizeX = $this.MbuttonSizeXY / 2
$this.RbuttonSizeY = $this.MbuttonSizeXY / 3
$this.RbuttonGapX = $this.MbuttonSizeXY / 10
$this.RbuttonGapY = $this.MbuttonSizeXY / 10
$this.textBoxSizeX = $this.MbuttonSizeXY * 2.5
$this.textBoxSizeY = $this.MbuttonSizeXY + $this.RbuttonSizeY * 2.985
#$this.textBoxSizeY = $this.MbuttonSizeXY * 1.992
$this.disBoxSizeX = $this.MbuttonSizeXY * 1.5
$this.disBoxSizeY = $this.MbuttonSizeXY + $this.RbuttonSizeY * 2.985
$this.lab1X = $this.MbuttonSizeXY - 1
$this.lab1Y = $this.labDrop
$this.lab2X = $this.MbuttonSizeXY * 2.5
$this.lab2Y = $this.labDrop
$this.lab3X = $this.MbuttonSizeXY * 1.5
$this.lab3Y = $this.labDrop
$this.MPointX = $this.RbuttonGapX
$this.MPointY = $this.labDrop + 1
$this.formSizeX = $this.MbuttonSizeXY * 5 + $this.RbuttonGapX * 3
$this.formSizeY = $this.MbuttonSizeXY * 2 + $this.RbuttonGapY * 4 + $this.MPointY
$this.formPX = 0 #but like center screen ... work it out
$this.topLabel1X = $this.RbuttonGapX
$this.topLabel2X = $this.MbuttonSizeXY + $this.RbuttonGapX
$this.topLabel3X = $this.MbuttonSizeXY * 3.5 + $this.RbuttonGapX * 1.1
$this.textBoxPX = $this.MbuttonSizeXY + $this.RbuttonGapX
$this.displayBoxX = $this.MbuttonSizeXY * 3.5 + $this.RbuttonGapX * 1.1
$this.mainMacroButtonX = $this.RbuttonGapX
$this.curButtonX = $this.RbuttonGapX
$this.autoButtonX = $this.RbuttonGapX + $this.RbuttonSizeX
$this.canButtonX = $this.RbuttonGapX
$this.fxlButtonX = $this.RbuttonGapX + $this.RbuttonSizeX
$this.clrButtonX = $this.RbuttonGapX
$this.backButtonX = $this.RbuttonGapX + $this.RbuttonSizeX
$this.formPY = 0
$this.topLabel1Y = $this.RbuttonGapY
$this.topLabel2Y = $this.RbuttonGapY
$this.topLabel3Y = $this.RbuttonGapY
$this.textBoxPY = $this.RbuttonGapY + $this.MPointY
$this.displayBoxY= $this.RbuttonGapY + $this.MPointY
$this.mainMacroButtonY = $this.RbuttonGapY + $this.MPointY
$this.curButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.MPointY
$this.autoButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.MPointY
$this.canButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.RbuttonSizeY + $this.MPointY
$this.fxlButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.RbuttonSizeY + $this.MPointY
$this.clrButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.RbuttonSizeY * 2 + $this.MPointY
$this.backButtonY = $this.RbuttonGapY + $this.MbuttonSizeXY + $this.RbuttonSizeY * 2 + $this.MPointY
}
[void]startForm()
{
$this.formP = New-Object System.Windows.Forms.Form
$this.formP.Text = 'AUTOMATIC PRINTING DIALOG'
$this.formP.Size = New-Object System.Drawing.Size( $this.formSizeX, $this.formSizeY )
$this.formP.StartPosition = 'CenterScreen'
$this.addMainTextBox()
$this.addDisplayBox()
$this.addMainMacroButton()
$this.addCanButton()
$this.addAutoButton()
$this.addCurButton()
$this.addFixButton()
$this.addClrButton()
$this.addBackButton()
$this.addLab1()
$this.addLab2()
$this.addLab3()
}
[void]shower()
{
$result = $this.formP.ShowDialog()
}
[void]closer()
{
$this.formP.close()
$this.formP.dispose()
}
[void]addMainTextBox()
{
$this.textBoxP = New-Object System.Windows.Forms.TextBox
$this.textBoxP.Location = New-Object System.Drawing.Point( $this.textBoxPX, $this.textBoxPY)
$this.textBoxP.Size = New-Object System.Drawing.Size( $this.textBoxSizeX, $this.textBoxSizeY)
$this.textBoxP.Multiline = $True
$this.textBoxP.AcceptsReturn = $True
$this.textBoxP.AcceptsTab = $True
#$this.textBoxP.Scrollbars ="Vertical"
#$this.textBoxZ.ReadOnly = "true"
$this.textBoxP.WordWrap = $True
$this.textBoxP.TextAlign = "Left"
$this.formP.Controls.Add($this.textBoxP)
}
[void]addDisplayBox()
{
$font3Box = New-Object System.Drawing.Font("Arial" , 10 , [System.Drawing.FontStyle]::Regular)
$this.displayBox1 = New-Object System.Windows.Forms.TextBox
$this.displayBox1.Location = New-Object System.Drawing.Point( $this.displayBoxX, $this.displayBoxY)
$this.displayBox1.Size = New-Object System.Drawing.Size( $this.disBoxSizeX, $this.disBoxSizeY)
$this.displayBox1.Multiline = $true
$this.displayBox1.AcceptsReturn = $true
$this.displayBox1.AcceptsTab = $true
$this.displayBox1.BackColor = 'darkslategray'
$this.displayBox1.Font = $font3Box
$this.displayBox1.BorderStyle = 'none'
$this.displayBox1.ReadOnly = $true
$this.displayBox1.ForeColor = "lime"
$this.formP.Controls.Add($this.displayBox1)
}
[void]addMainMacroButton()
{
$fontBBX = New-Object System.Drawing.Font("Arial" , 12 , [System.Drawing.FontStyle]::BOLD)
$this.mainMacroButton = New-Object System.Windows.Forms.Button
$this.mainMacroButton.Location = New-Object System.Drawing.Point($this.mainMacroButtonX,$this.mainMacroButtonY)
$this.mainMacroButton.Size = New-Object System.Drawing.Size($this.MbuttonSizeXY,$this.MbuttonSizeXY)
$this.mainMacroButton.Text = 'MAINAUTO'
$this.mainMacroButton.font = $fontBBX
$this.mainMacroButton.backcolor = "indianred"
$this.formP.Controls.Add($this.mainMacroButton)
$thisMAINMACROBUTTON = $this
$this.mainMacroButton.add_click({
$thisMAINMACROBUTTON.mainAutoClick()
}.GetNewClosure())
}
[void]addCanButton()
{
$this.canButton = New-Object System.Windows.Forms.Button
$this.canButton.Location = New-Object System.Drawing.Point($this.canButtonX,$this.canButtonY)
$this.canButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.canButton.Text = 'CANCEL'
$this.canButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$this.canButton.BackColor = "black"
$this.canButton.forecolor = "indianred"
$this.formP.CancelButton = $this.canButton
$this.formP.Controls.Add($this.canButton)
}
[void]addAutoButton()
{
$this.autoButton = New-Object System.Windows.Forms.Button
$this.autoButton.Location = New-Object System.Drawing.Point($this.autoButtonX,$this.autoButtonY)
$this.autoButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.autoButton.Text = 'AUTO'
$this.autoButton.backcolor = "indianred"
$this.formP.Controls.Add($this.autoButton)
$thisAUTOBUTTON = $this
$this.autoButton.add_click({
$thisAUTOBUTTON.autoClick()
}.GetNewClosure())
}
[void]addCurButton()
{
$this.curButton = New-Object System.Windows.Forms.Button
$this.curButton.Location = New-Object System.Drawing.Point($this.curButtonX,$this.curButtonY)
$this.curButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.curButton.Text = 'CUR'
$this.curButton.BackColor = "indianred"
$this.formP.Controls.Add($this.curButton)
$thisCURBUTTON = $this
$this.curButton.add_click({
$thisCURBUTTON.curClick()
}.GetNewClosure())
}
[void]addFixButton()
{
$this.fxlButton = New-Object System.Windows.Forms.Button
$this.fxlButton.Location = New-Object System.Drawing.Point($this.fxlButtonX,$this.fxlButtonY)
$this.fxlButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.fxlButton.Text = 'FIX'
$this.fxlButton.BackColor = "ForestGreen"
$this.fxlButton.ForeColor = "Lime"
$this.formP.Controls.Add($this.fxlButton)
$thisformFXLBUTTON = $this
$this.fxlButton.add_click({
$thisformFXLBUTTON.fixClick()
}.GetNewClosure())
}
[void]addClrButton()
{
$this.clrButton = New-Object System.Windows.Forms.Button
$this.clrButton.Location = New-Object System.Drawing.Point($this.clrButtonX,$this.clrButtonY)
$this.clrButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.clrButton.Text = 'CLR'
$this.clrButton.BackColor = "black"
$this.clrButton.forecolor = "indianred"
$this.formP.Controls.Add($this.clrButton)
$thisformCLRBUTTON = $this
$this.clrButton.add_click({
$thisformCLRBUTTON.clrClick()
}.GetNewClosure())
}
[void]addBackButton()
{
$this.backButton = New-Object System.Windows.Forms.Button
$this.backButton.Location = New-Object System.Drawing.Point($this.backButtonX,$this.backButtonY)
$this.backButton.Size = New-Object System.Drawing.Size($this.RbuttonSizeX,$this.RbuttonSizeY)
$this.backButton.Text = 'BACK'
$this.backButton.BackColor = "green"
$this.formP.Controls.Add($this.backButton)
$thisBACKBUTTON = $this
$this.backButton.add_click({
$thisBACKBUTTON.backClick()
}.GetNewClosure())
}
[void]addLab1()
{
$fontLab1 = New-Object System.Drawing.Font("Arial" , 8 , [System.Drawing.FontStyle]::BOLD)
$this.topLabel1 = New-Object System.Windows.Forms.Label
$this.topLabel1.Location = New-Object System.Drawing.Point($this.topLabel1X, $this.topLabel1Y)
$this.topLabel1.Size = New-Object System.Drawing.Size( $this.lab1X ,$this.lab1Y )
$this.topLabel1.Font = $fontLab1
$this.topLabel1.ForeColor = "snow"
$this.topLabel1.BackColor = "dodgerBlue"
$this.topLabel1.Text = ''
$this.formP.Controls.Add($this.topLabel1)
}
[void]addLab2()
{
$fontLab2 = New-Object System.Drawing.Font("Arial" , 8 , [System.Drawing.FontStyle]::BOLD)
$this.topLabel2 = New-Object System.Windows.Forms.Label
$this.topLabel2.Location = New-Object System.Drawing.Point($this.topLabel2X, $this.topLabel2Y)
$this.topLabel2.Size = New-Object System.Drawing.Size( $this.lab2X ,$this.lab2Y )
$this.topLabel2.Font = $fontLab2
$this.topLabel2.ForeColor = "black"
$this.topLabel2.BackColor = "indianred"
$this.topLabel2.Text = 'NOT READY TO PRINT YET'
$this.formP.Controls.Add($this.topLabel2)
}
[void]addLab3()
{
$fontLab3 = New-Object System.Drawing.Font("Arial" , 8 , [System.Drawing.FontStyle]::BOLD)
$this.topLabel3 = New-Object System.Windows.Forms.Label
$this.topLabel3.Location = New-Object System.Drawing.Point($this.topLabel3X, $this.topLabel3Y)
$this.topLabel3.Size = New-Object System.Drawing.Size( $this.lab3X ,$this.lab3Y )
$this.topLabel3.Font = $fontLab3
$this.topLabel3.ForeColor = "black"
$this.topLabel3.BackColor = "indianred"
$this.topLabel3.Text = 'DONT MISS WHEN IN MACRO!!! USE NOTEPAD!'
$this.formP.Controls.Add($this.topLabel3)
}
fixClick( ) #enable the security bypass by setexecutionpolicy -scope currentuser etc...
{
#don't get me wrong security here can be henious...
$newFile1 = $this.newTextDone
$newFile2 = $this.newText
$backTextD = $this.backTextDone
$backText1 = $this.backText
$deal = Test-Path -Path $newFile1
$deal2 = Test-Path -Path $newFile2
$deal3 = Test-Path -Path $backText1
$deal4 = Test-Path -Path $backTextD
if($deal -eq $true)
{
remove-item $newFile1
}
if($deal2 -eq $true)
{
remove-item $newFile2
}
if($deal3 -eq $true)
{
remove-item $backText1
}
if($deal4 -eq $true)
{
remove-item $backTextD
}
$happy = $this.textBoxP.Text
$happy >> $newFile2
$happy >> $backText1
$listFxr = $this.cacName + "\listfixer.ps1"
$powershellArguments = $listFxr
cd $this.cacName
<#
$placeListFixer = ".\listfixer.ps1"
Unblock-File -Path "$placeListFixer"
Start-Process powershell "$placeListFixer" -Wait -WindowStyle Hidden
#>
$thisLISTFIXER = $this
$thisLISTFIXER.fixLists()
$horseX = [string](Get-content -path $newFile1 )
$spiltHorse = $horseX.Split()
$accu = ""
foreach($goget in $spiltHorse)
{
$accu += $goget
$accu += "`r`n"
}
$this.displayBox1.text = $accu
$this.fxlButton.BackColor = "ForestGreen"
$this.autoButton.backcolor = "forestgreen"
$this.mainMacroButton.backcolor = "forestgreen"
$this.backButton.backcolor = "indigo"
$this.backButton.foreColor = "lime"
$this.curButton.backColor = "forestGreen"
$this.curButton.foreColor = "black"
$this.topLabel2.ForeColor = "midnightblue"
$this.topLabel2.BackColor = "forestGreen"
$this.topLabel2.Text = "READY TO PRINT SOMETHING"
$this.topLabel3.ForeColor = "midnightblue"
$this.topLabel3.BackColor = "forestGreen"
$this.topLabel3.Text = "DONT MISS WHEN IN MACRO!!! USE NOTEPAD!"
}
clrClick()
{
$this.displayBox1.text = ""
$this.textBoxP.text = ""
$newFile1 = $this.newTextDone
$newFile2 = $this.newText
$dealy = Test-Path -Path $newFile1
$deal2y = Test-Path -Path $newFile2
if($dealy -eq $true)
{
remove-item $newFile1
}
if($deal2y -eq $true)
{
remove-item $newFile2
}
$this.autoButton.backcolor = "indianred"
$this.mainMacroButton.backcolor = "indianred"
$this.curButton.BackColor = "indianred"
$this.topLabel2.ForeColor = "black"
$this.topLabel2.BackColor = "indianred"
$this.topLabel2.Text = "NOTHING TO PRINT"
$this.topLabel3.ForeColor = "black"
$this.topLabel3.BackColor = "indianred"
$this.topLabel3.Text = "DONT MISS WHEN IN MACRO!!! USE NOTEPAD!"
}
curClick()
{
$newFile1 = $this.newTextDone
$newFile2 = $this.newText
$deay = Test-Path -Path $newFile1
$dea2y = Test-Path -Path $newFile2
if($dea2y -eq $true)
{
$this.displayBox1.text = ""
$horseX = [string](Get-content -path $newFile2 )
$spiltHorse = $horseX.Split()
$accu = ""
foreach($goget in $spiltHorse)
{
$accu += $goget
$accu += "`r`n"
}
$this.displayBox1.text = $accu
}
if($deay -eq $true)
{
$this.textboxP.text = ""
$horseX2 = [string](Get-content -path $newFile2 )
$spiltHorse = $horseX2.Split()
$accu = ""
foreach($goget in $spiltHorse)
{
$accu += $goget
$accu += "`r`n"
}
$this.textboxP.text = $accu
}
}
autoClick()
{
if($this.topLabel2.BackColor -ne "IndianRed" )
{
Start-Process notepad
$fontBB = New-Object System.Drawing.Font("Arial" , 48 , [System.Drawing.FontStyle]::BOLD)
$this.mainMacroButton.font = $fontBB
$this.mainMacroButton.backcolor ="black"
$this.mainMacroButton.forecolor = "red"
$this.topLabel2.backcolor = "black"
$this.topLabel2.forecolor = "red"
$this.topLabel2.text = "MACRO IS ABOUT TO GO!"
$this.topLabel3.backcolor = "black"
$this.topLabel3.forecolor = "dodgerblue"
$this.mainMacroButton.text = "4"
Start-Sleep -Seconds 1
$this.mainMacroButton.text = "3"
Start-Sleep -Seconds 1
$this.mainMacroButton.text = "2"
Start-Sleep -Seconds 1
$this.mainMacroButton.text = "1"
Start-Sleep -Seconds 1
$fontBA = New-Object System.Drawing.Font("Arial" , 22 , [System.Drawing.FontStyle]::BOLD)
$this.mainMacroButton.font = $fontBA
$this.mainMacroButton.text = "MACRO!"
$fontBBXX = New-Object System.Drawing.Font("Arial" , 12 , [System.Drawing.FontStyle]::BOLD)
<#
cd $this.cacName
$placeAutoClicker = ".\autoShootPrinting.ps1"
unblock-file -Path "$placeAutoClicker"
Start-Process powershell $placeAutoClicker -Wait -WindowStyle Hidden
Start-Sleep -Seconds 1
#>
$thisAPRINTER = $this
$thisAPRINTER.autoprinting()
$this.mainMacroButton.Text = 'MAINAUTO'
$this.mainMacroButton.font = $fontBBXX
$this.mainMacroButton.backcolor = "indianred"
$this.mainMacroButton.forecolor = "black"
$this.topLabel2.ForeColor = "black"
$this.topLabel2.BackColor = "indianred"
$this.topLabel2.text = "NOT READY TO PRINT YET"
$this.topLabel3.ForeColor = "black"
$this.topLabel3.BackColor = "indianred"
$this.topLabel3.Text = 'DONT MISS WHEN IN MACRO!!! USE NOTEPAD!'
}
}
mainAutoClick()
{
$thisFix = $this
$thisFix.fixClick()
$thisAuto =$this
$thisAuto.autoClick()
$thisClr = $this
$thisClr.clrClick()
Stop-Process -Name notepad
}
backClick()
{
$backFileO = $this.backText
$deay = Test-Path -Path $backFileO
$horseB = [string](Get-content -path $backFileO )
if($deay -eq $true)
{
$this.textBoxP.text = $horseB
}
}
autoprinting()
{
$newFileAP = $this.newTextDone
$catZX = gc $newFileAP
$lCatZX = $catZX.Length
$rottenZX = ""
for ( ($i = 0) ; $i -lt $lCatZX ; $i++ )
{
if($i -ne ($lCatZX - 1 ) )
{
$hookyZX = $catZX[$i]
$hooky2ZX = $catZX[$i + 1]
$this.topLabel3.text = $hookyZX
#Set-Clipboard -Value ($hooky)
#$sexcZX = 340
$sexcZX = 270
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait($hookyZX)
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
Start-Sleep -Milliseconds $sexcZX
#[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
#Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -Milliseconds $sexcZX
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
Start-Sleep -Milliseconds $sexcZX
$rottenZX = $rottenZX + $hookyZX
$hookyZX = ""
}
}
}
fixLists()
{
$newFileFLD = $this.newTextDone
$newFileFL = $this.newText
$backTextFL = $this.backTextDone
$horseXX = [string](Get-content -path $newFileFL )
$dogsX = $horseXX
$popX = 1
$hookyX = ""
$hooky2X = ""
$fudX = ""
$catCX = $dogsX.Length
for ( $i = 0; $i -lt $catCX ; $i++)
{
if($i -ne ($catCX - 1 ) )
{
$hookyX = $dogsX[$i]
$hooky2X = $dogsX[$i + 1]
if ( $hookyX -ne " " -and $hookyX -ne "`t")
{
$fudX = $fudX + $hookyX
}
if ( $hookyX -eq "`t")
{
#$fud = $fud + "`n"
$fudX >> $newFileFLD
$fudx >> $backTextFL
$popX = $popX + 1
$fudX = ""
}
}
}
$fudX = $fudX + "`n"
$fudX >> $newFileFLD
$fudx >> $backTextFL
}
}
#$aNewSheet = [autoPrintForm]::new()
$aNewSheet = [autoPrintForm]::new(185)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.