在用户成功提交请求后,如何让表单重置/关闭?我正在使用Powershell ise进行测试,脚本永远不会关闭,直到我真的X出来。这是我目前的职能。
感谢本论坛上的人们,我的表格正常运作。我有另一个问题,我正在努力。如何在用户点击提交按钮后重置表单?我当前必须退出表单才能结束脚本。
#region gui events {
$btn1.Add_Click({ sendRequest; thankyou })
#endregion events }
#endregion GUI }
function sendRequest()
{
# API Key
$FDApiKey="api key"
#################################################
# Force TLS1.2 as Powershell defaults to TLS 1.0 and Freshdesk will fail connections
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
# Prep
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
##################################################
$Body = @{
description = $description.Text
email = $email.Text
subject = $subject.Text
type = $request.Text
priority = 1
status = 2
}
Invoke-WebRequest "https://clasd.freshdesk.com/api/v2/tickets/" `
-Headers $FDHeaders `
-ContentType "application/json" `
-Method Post `
-Body ($Body | ConvertTo-JSON)
}
function thankyou ()
{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
}
#Write your logic code here
[void]$Form.ShowDialog()
答案 0 :(得分:3)
如果没有看到表单上的所有控件,就不可能为您提供完整的代码,但这应该为您提供基本的想法。
function thankyou{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
$description.Text = ''
$email.Text = ''
$subject.Text = ''
$request.Text = ''
}
答案 1 :(得分:0)
这是一个在单击按钮后关闭表单的简单示例。
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({$form.Close()}) #add any other logic you require to the button click's anonymous function
$form.Controls.Add($button)
$form.ShowDialog()
要动态访问按钮的表单,而不是将实际引用传递给表单,您可以执行以下操作:
function OnButtonClick {
$theForm = $this.Parent
$theForm.DialogResult = [System.Windows.Forms.DialogResult]::OK
$theForm.Close()
}
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({OnButtonClick})
$form.Controls.Add($button)
$form.ShowDialog()