0

用户成功提交请求后,如何让表单重置/关闭?我正在使用 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()
4

2 回答 2

3

如果不查看表单上的所有控件,实际上不可能为您提供完整的代码,但这应该会给您基本的想法。

function thankyou{
  [System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
  $description.Text = ''
  $email.Text = ''
  $subject.Text = ''
  $request.Text = ''
}
于 2018-04-17T12:30:09.337 回答
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()
于 2018-04-17T12:43:14.207 回答