此表单上的“确定”按钮是否可以始终位于右下角?完全公开代码是从快速谷歌搜索中获得的。我想要完成的是我通过单击我的主表单的按钮启动了这个(下)辅助表单。如果被抓取的请求很多,那么 OK 按钮就会到处都是。
function openrequests {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$dataGrid1 = New-Object System.Windows.Forms.DataGridView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick= {
#TODO: Place custom script here
}
# API Key
$FDApiKey="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-RestMethod -uri "https://clasd.freshdesk.com/api/v2/tickets?email=xyz@clasd.net&order_by=status" -Headers $FDHeaders -ContentType application/json -Method Get | Convertto-json | Out-File c:\temp\mytickets.txt
$file = "c:\temp\mytickets.txt"
$data = Get-Content $file -Raw | ConvertFrom-Json | Select-Object -Expand Value
$handler_form1_Load=
{
$list=[system.collections.arraylist]($data | select id, subject, description_text)
$datagrid1.DataSource=$list
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "My Tickets"
$form1.Name = "form1"
$form1.AutoSize = $true
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
#$System_Drawing_Size.Width = 416
#$System_Drawing_Size.Height = 512
#$form1.ClientSize = $System_Drawing_Size
$form1.add_Load($handler_form1_Load)
$button1.TabIndex = 1
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $False
$button1.Text = "Ok"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 300
$System_Drawing_Point.Y = 469
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.DialogResult = 1
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$System_Drawing_Size = New-Object System.Drawing.Size
#$System_Drawing_Size.Width = 280
#$System_Drawing_Size.Height = 633
$dataGrid1.AutoSize = $true
$dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
#$dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid1.Name = "dataGrid1"
$dataGrid1.DataMember = ""
$dataGrid1.TabIndex = 0
$dataGrid1.DefaultCellStyle.WrapMode = [System.Windows.Forms.DataGridViewTriState]::True
$dataGrid1.AutoSizeRowsMode = [System.Windows.Forms.DataGridViewAutoSizeRowsMode]::AllCells
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1
$System_Drawing_Point.Y = 12
$dataGrid1.Location = $System_Drawing_Point
$form1.Controls.Add($dataGrid1)
$form1.Add_Shown({$form1.Activate();$dataGrid1.AutoResizeColumns()})
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
#GenerateForm
#Write your logic code here