Iniciamos o script, como de costume:
Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing [Windows.Forms.Application]::EnableVisualStyles()
Criamos o Form:
# #Form0 # $Form0 = New-Object System.Windows.Forms.Form $Form0.Text = "Controls" $Form0.ClientSize = New-Object System.Drawing.Size(373, 356)
Na sequência, vamos adicionar os seguintes controles: button, checkbox, combobox, label, radiobutton, richtextbox, textbox, datetimepicker. Observe que a adição ao Form [$Form0] se dá através de $Form0.Controls.Add(Objeto_que_representa_o_controle).
Adicionamos um botão [button]:
# #Button0 # $Button0 = New-Object System.Windows.Forms.Button $Button0.Text = "Button" $Button0.Size = New-Object System.Drawing.Size(75, 42) $Button0.Location = New-Object System.Drawing.Point(18, 40) $Form0.Controls.Add($Button0)
Adicionamos checkbox:
# #CheckBox0 # $CheckBox0 = New-Object System.Windows.Forms.CheckBox $CheckBox0.Text = "CheckBox" $CheckBox0.Size = New-Object System.Drawing.Size(104, 24) $CheckBox0.Location = New-Object System.Drawing.Point(110, 48) $Form0.Controls.Add($CheckBox0)
Adicionamos combobox
# #ComboBox0 # $ComboBox0 = New-Object System.Windows.Forms.ComboBox $ComboBox0.Text = "ComboBox" $ComboBox0.Size = New-Object System.Drawing.Size(121, 21) $ComboBox0.Location = New-Object System.Drawing.Point(222, 50) $Form0.Controls.Add($ComboBox0)
Adicionamos um label:
# #Label0 # $Label0 = New-Object System.Windows.Forms.Label $Label0.AutoSize = $true $Label0.Font = New-Object System.Drawing.Font("Arial", 14, [System.Drawing.FontStyle]::Bold) $Label0.Text = "Eu sou um LABEL" $Label0.Size = New-Object System.Drawing.Size(313, 27) $Label0.Location = New-Object System.Drawing.Point(15, 9) $Form0.Controls.Add($Label0)
Adicionamos um radiobutton:
# #RadioButton0 # $RadioButton0 = New-Object System.Windows.Forms.RadioButton $RadioButton0.Text = "RadioButton" $RadioButton0.Size = New-Object System.Drawing.Size(104, 24) $RadioButton0.Location = New-Object System.Drawing.Point(110, 86) $Form0.Controls.Add($RadioButton0)
Adicionamos richtextbox:
# #RichTextBox0 # $RichTextBox0 = New-Object System.Windows.Forms.RichTextBox $RichTextBox0.Text = "RichTextBox" $RichTextBox0.Size = New-Object System.Drawing.Size(100, 50) $RichTextBox0.Location = New-Object System.Drawing.Point(221, 89) $Form0.Controls.Add($RichTextBox0)
Adicionamos textbox:
# #TextBox0 # $TextBox0 = New-Object System.Windows.Forms.TextBox $TextBox0.Text = "TextBox" $TextBox0.Size = New-Object System.Drawing.Size(100, 20) $TextBox0.Location = New-Object System.Drawing.Point(19, 121) $Form0.Controls.Add($TextBox0)
Adicionamos datetimepicker:
# #DateTimePicker0 # $DateTimePicker0 = New-Object System.Windows.Forms.DateTimePicker $DateTimePicker0.Size = New-Object System.Drawing.Size(200, 20) $DateTimePicker0.Location = New-Object System.Drawing.Point(20, 167) $Form0.Controls.Add($DateTimePicker0)
Por fim, exibimos o Form:
[void]$Form0.ShowDialog()
A seguir, um video demonstrando também a adição de Controls a um Form:
[Acesso ao código do vídeo]
Nenhum comentário:
Postar um comentário