我的腳本接受 3 個數字輸入并相應地執行功能。現在,如果我有新的數字要輸入,我需要停止整個腳本并重新運行。如何使用同一會話輸入新號碼?
Add-Type -assembly System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$main_form = New-Object System.Windows.Forms.Form
# Box size
$main_form.Text ='ABC Pattern Calculator'
$main_form.Width = 450
$main_form.Height = 350
$main_form.AutoSize = $true
# Label1
$intitalLabel = New-Object System.Windows.Forms.Label
$intitalLabel.Text = "Click on Bull or Bear tab"
$intitalLabel.Location = New-Object System.Drawing.Point(30,20)
$intitalLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$intitalLabel.AutoSize = $true
$main_form.Controls.Add($intitalLabel)
############################# TABS #######################################
# Tab master control
$MainTab = New-Object System.Windows.Forms.TabControl
$MainTab.Size = '400,250'
$MainTab.Location = '30,50'
$MainTab.Multiline = $true
$MainTab.AutoSize = $true
$MainTab.Anchor = 'Top,Left,Bottom,Right'
# Tab pages
$TabPage1 = New-Object System.Windows.Forms.TabPage
$Tabpage1.TabIndex = 1
$Tabpage1.Text = 'Bullish Pattern'
$TabPage1.Name = 'Tab1'
$TabPage2 = New-Object System.Windows.Forms.TabPage
$Tabpage2.TabIndex = 2
$Tabpage2.Text = 'Bearish Pattern'
$TabPage2.Name = 'Tab2'
# Add tabs to tab control
$MainTab.Controls.AddRange(@($TabPage1,$TabPage2))
$main_form.controls.Add($MainTab)
########################## Bull Tab #######################################
# Textbox = Point A
$aBullTextbox = New-Object System.Windows.Forms.TextBox
$aBullTextbox.Location = New-Object System.Drawing.Point(82,30)
$aBullTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($aBullTextbox)
# Textbox = Point B
$bBullTextbox = New-Object System.Windows.Forms.TextBox
$bBullTextbox.Location = New-Object System.Drawing.Point(82,80)
$bBullTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($bBullTextbox)
# Textbox = Point C
$cBullTextbox = New-Object System.Windows.Forms.TextBox
$cBullTextbox.Location = New-Object System.Drawing.Point(82,136)
$cBullTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($cBullTextbox)
# Label1
$aBullLabel = New-Object System.Windows.Forms.Label
$aBullLabel.Text = "A Low:"
$aBullLabel.Location = New-Object System.Drawing.Point(10,30)
$aBullLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$aBullLabel.AutoSize = $true
$main_form.Controls.Add($aBullLabel)
# Label2
$bBullLabel = New-Object System.Windows.Forms.Label
$bBullLabel.Text = "B High:"
$bBullLabel.Location = New-Object System.Drawing.Point(10,80)
$bBullLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$bBullLabel.AutoSize = $true
$main_form.Controls.Add($bBullLabel)
# Label3
$cBullLabel = New-Object System.Windows.Forms.Label
$cBullLabel.Text = "C Low:"
$cBullLabel.Location = New-Object System.Drawing.Point(10,136)
$cBullLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$cBullLabel.AutoSize = $true
$main_form.Controls.Add($cBullLabel)
# Radio button = Calculate
$bullCalculateButton = New-Object System.Windows.Forms.Button
$bullCalculateButton.Location = New-Object System.Drawing.Size(50,180)
$bullCalculateButton.Size = New-Object System.Drawing.Size(110,23)
$bullCalculateButton.Text = "Calculate"
$main_form.Controls.Add($bullCalculateButton)
# Math function
$bullCalculateButton.Add_Click({
$aBullCalc = $aBullTextbox.Text
$bBullCalc = $bBullTextbox.Text
$cBullCalc = $cBullTextbox.Text
$pointD = $bBullCalc - $aBullCalc $cBullCalc
# D Label
$dBullLabel = New-Object System.Windows.Forms.Label
$dBullLabel.Text = "Point D will be at:"
$dBullLabel.Location = New-Object System.Drawing.Point(230,50)
$dBullLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$dBullLabel.AutoSize = $true
$main_form.Controls.Add($dBullLabel)
# Answer to D
$dcalcLabel = New-Object System.Windows.Forms.Label
$dcalcLabel.Text = $pointD
$dcalcLabel.Location = New-Object System.Drawing.Point(280,70)
$dcalcLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$dcalcLabel.AutoSize = $true
$main_form.Controls.Add($dcalcLabel)
$TabPage1.Controls.AddRange(@($dcalcLabel,$dBullLabel))
})
$TabPage1.Controls.AddRange(@($aBullTextbox,$bBullTextbox,$cBullTextbox,$aBullLabel,$bBullLabel,$cBullLabel,$bullCalculateButton))
########################## Bear Tab #######################################
# Textbox = Point A
$aBearTextbox = New-Object System.Windows.Forms.TextBox
$aBearTextbox.Location = New-Object System.Drawing.Point(82,30)
$aBearTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($aBearTextbox)
# Textbox = Point B
$bBearTextbox = New-Object System.Windows.Forms.TextBox
$bBearTextbox.Location = New-Object System.Drawing.Point(82,80)
$bBearTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($bBearTextbox)
# Textbox = Point C
$cBearTextbox = New-Object System.Windows.Forms.TextBox
$cBearTextbox.Location = New-Object System.Drawing.Point(82,136)
$cBearTextbox.Size = New-Object System.Drawing.Size(140)
$main_form.StartPosition = 'CenterScreen'
$main_form.Controls.Add($cBearTextbox)
# Label1
$aBearLabel = New-Object System.Windows.Forms.Label
$aBearLabel.Text = "A High:"
$aBearLabel.Location = New-Object System.Drawing.Point(10,30)
$aBearLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$aBearLabel.AutoSize = $true
$main_form.Controls.Add($aBearLabel)
# Label2
$bBearLabel = New-Object System.Windows.Forms.Label
$bBearLabel.Text = "B Low:"
$bBearLabel.Location = New-Object System.Drawing.Point(10,80)
$bBearLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$bBearLabel.AutoSize = $true
$main_form.Controls.Add($bBearLabel)
# Label3
$cBearLabel = New-Object System.Windows.Forms.Label
$cBearLabel.Text = "C High:"
$cBearLabel.Location = New-Object System.Drawing.Point(10,136)
$cBearLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$cBearLabel.AutoSize = $true
$main_form.Controls.Add($cBearLabel)
# Radio button = Calculate
$BearCalculateButton = New-Object System.Windows.Forms.Button
$BearCalculateButton.Location = New-Object System.Drawing.Size(50,180)
$BearCalculateButton.Size = New-Object System.Drawing.Size(110,23)
$BearCalculateButton.Text = "Calculate"
$main_form.Controls.Add($BearCalculateButton)
# Math function
$BearCalculateButton.Add_Click({
$aBearCalc = $aBearTextbox.Text
$bBearCalc = $bBearTextbox.Text
$cBearCalc = $cBearTextbox.Text
$pointDbear = $aBearCalc - $bBearCalc - $cBearCalc
# D Label
$dbearLabel = New-Object System.Windows.Forms.Label
$dbearLabel.Text = "Point D will be at:"
$dbearLabel.Location = New-Object System.Drawing.Point(230,50)
$dbearLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$dbearLabel.AutoSize = $true
$main_form.Controls.Add($dbearLabel)
# Answer to D
$dbearcalcLabel = New-Object System.Windows.Forms.Label
$dbearcalcLabel.Text = $pointDbear
$dbearcalcLabel.Location = New-Object System.Drawing.Point(280,70)
$dbearcalcLabel.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
$dbearcalcLabel.AutoSize = $true
$main_form.Controls.Add($dbearcalcLabel)
$TabPage2.Controls.AddRange(@($dbearcalcLabel,$dbearLabel))
})
$TabPage2.Controls.AddRange(@($aBearTextbox,$bBearTextbox,$cBearTextbox,$aBearLabel,$bBearLabel,$cBearLabel,$BearCalculateButton))
# To show the box
$main_form.ShowDialog()
我的腳本接受 3 個數字輸入并相應地執行功能。現在,如果我有新的數字要輸入,我需要停止整個腳本并重新運行。如何使用同一會話輸入新號碼?
uj5u.com熱心網友回復:
您可以通過僅在事件外部將標簽添加到主表單一次.Add_Click來簡化它,然后在事件內部您可以進行計算并更新它們的.Text屬性。此示例演示如何為“看漲模式”選項卡執行此操作,您可以按照此示例對“看跌模式”選項卡執行相同操作:
# Both labels are now outside the Event!
$dBullLabel = [Windows.Forms.Label]@{
Text = ''
Location = [Drawing.Point]::new(230, 50)
Font = [Drawing.Font]::new("Microsoft Sans Serif", 12, [Drawing.FontStyle]::Bold)
AutoSize = $true
}
$dcalcLabel = [Windows.Forms.Label]@{
Text = ''
Location = [Drawing.Point]::new(280, 70)
Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [Drawing.FontStyle]::Bold)
AutoSize = $true
}
$main_form.Controls.AddRange(@($dBullLabel, $dcalcLabel))
$TabPage1.Controls.AddRange(@($dcalcLabel, $dBullLabel))
$bullCalculateButton.Add_Click({
# Inside the event, we do just calculation
$pointD = [double] $aBullTextbox.Text - $bBullTextbox.Text - $cBullTextbox.Text
# and update
$dBullLabel.Text = "Point D will be at:"
$dcalcLabel.Text = $pointD
})

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/524871.html
標籤:电源外壳
上一篇:RabbitMQ
