actualice el ejemplo con muchos controles y menus hasta grids
esto lo puedes generar fácilmente con copilot que es especialsita en windows
solo le pides que quieres hacer y listo
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
#===========================================================
# FUNCIONES DE DEMO
#===========================================================
function Show-TextBoxDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo TextBox"
$form.Size = "400,250"
$form.StartPosition = "CenterScreen"
$form.BackColor = "LightBlue"
$label = New-Object System.Windows.Forms.Label
$label.Text = "Escribe tu nombre:"
$label.Location = "20,20"
$label.AutoSize = $true
$textbox = New-Object System.Windows.Forms.TextBox
$textbox.Location = "20,50"
$textbox.Width = 250
$button = New-Object System.Windows.Forms.Button
$button.Text = "Saludar"
$button.Location = "20,90"
$button.BackColor = "LightGreen"
$button.Add_Click({
[System.Windows.Forms.MessageBox]::Show("Hola, $($textbox.Text)!")
})
$form.Controls.AddRange(@($label,$textbox,$button))
$form.ShowDialog()
}
function Show-SliderDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo Slider"
$form.Size = "400,200"
$form.StartPosition = "CenterScreen"
$form.BackColor = "Lavender"
$track = New-Object System.Windows.Forms.TrackBar
$track.Location = "20,20"
$track.Minimum = 0
$track.Maximum = 100
$track.Width = 300
$label = New-Object System.Windows.Forms.Label
$label.Location = "20,70"
$label.AutoSize = $true
$label.Text = "Valor: 0"
$track.Add_ValueChanged({
$label.Text = "Valor: $($track.Value)"
})
$form.Controls.AddRange(@($track,$label))
$form.ShowDialog()
}
function Show-ListViewDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo ListView"
$form.Size = "450,300"
$form.StartPosition = "CenterScreen"
$form.BackColor = "MistyRose"
$list = New-Object System.Windows.Forms.ListView
$list.View = "Details"
$list.FullRowSelect = $true
$list.GridLines = $true
$list.Size = "400,200"
$list.Location = "20,20"
$list.Columns.Add("ID",50)
$list.Columns.Add("Nombre",150)
$list.Columns.Add("Ciudad",150)
$items = @(
"1;Ciro;Davie",
"2;Ana;Miami",
"3;Juan;Orlando"
)
foreach ($i in $items) {
$parts = $i.Split(";")
$item = New-Object System.Windows.Forms.ListViewItem($parts[0])
$item.SubItems.Add($parts[1])
$item.SubItems.Add($parts[2])
$list.Items.Add($item)
}
$form.Controls.Add($list)
$form.ShowDialog()
}
function Show-GridDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo DataGridView"
$form.Size = "550,300"
$form.StartPosition = "CenterScreen"
$form.BackColor = "Honeydew"
$grid = New-Object System.Windows.Forms.DataGridView
$grid.Size = "500,200"
$grid.Location = "20,20"
$grid.AutoSizeColumnsMode = "Fill"
$table = New-Object System.Data.DataTable
$table.Columns.Add("Producto")
$table.Columns.Add("Precio")
$table.Columns.Add("Stock")
$table.Rows.Add("Laptop","1200","5")
$table.Rows.Add("Mouse","20","50")
$table.Rows.Add("Teclado","35","30")
$grid.DataSource = $table
$form.Controls.Add($grid)
$form.ShowDialog()
}
function Show-ComboDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo ComboBox"
$form.Size = "350,200"
$form.StartPosition = "CenterScreen"
$form.BackColor = "LightYellow"
$combo = New-Object System.Windows.Forms.ComboBox
$combo.Location = "20,20"
$combo.Width = 200
$combo.Items.AddRange(@("Rojo","Verde","Azul","Negro","Blanco"))
$button = New-Object System.Windows.Forms.Button
$button.Text = "Seleccionar"
$button.Location = "20,60"
$button.BackColor = "LightCoral"
$button.Add_Click({
[System.Windows.Forms.MessageBox]::Show("Elegiste: $($combo.SelectedItem)")
})
$form.Controls.AddRange(@($combo,$button))
$form.ShowDialog()
}
function Show-CheckRadioDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo CheckBox / RadioButton"
$form.Size = "350,250"
$form.StartPosition = "CenterScreen"
$form.BackColor = "LightCyan"
$chk = New-Object System.Windows.Forms.CheckBox
$chk.Text = "Activar opcion"
$chk.Location = "20,20"
$rb1 = New-Object System.Windows.Forms.RadioButton
$rb1.Text = "Opcion A"
$rb1.Location = "20,60"
$rb2 = New-Object System.Windows.Forms.RadioButton
$rb2.Text = "Opcion B"
$rb2.Location = "20,90"
$button = New-Object System.Windows.Forms.Button
$button.Text = "Mostrar seleccion"
$button.Location = "20,130"
$button.BackColor = "Khaki"
$button.Add_Click({
$msg = "CheckBox: " + ($chk.Checked)
$msg += "`nRadio: "
if ($rb1.Checked) { $msg += "A" }
elseif ($rb2.Checked) { $msg += "B" }
else { $msg += "Ninguno" }
[System.Windows.Forms.MessageBox]::Show($msg)
})
$form.Controls.AddRange(@($chk,$rb1,$rb2,$button))
$form.ShowDialog()
}
function Show-CalendarDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo Calendario"
$form.Size = "350,300"
$form.StartPosition = "CenterScreen"
$form.BackColor = "LavenderBlush"
$cal = New-Object System.Windows.Forms.MonthCalendar
$cal.Location = "20,20"
$form.Controls.Add($cal)
$form.ShowDialog()
}
function Show-ProgressDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo ProgressBar"
$form.Size = "350,200"
$form.StartPosition = "CenterScreen"
$form.BackColor = "MintCream"
$progress = New-Object System.Windows.Forms.ProgressBar
$progress.Location = "20,20"
$progress.Width = 250
$progress.Minimum = 0
$progress.Maximum = 100
$button = New-Object System.Windows.Forms.Button
$button.Text = "Iniciar"
$button.Location = "20,60"
$button.BackColor = "LightSkyBlue"
$button.Add_Click({
for ($i=0; $i -le 100; $i+=5) {
$progress.Value = $i
Start-Sleep -Milliseconds 100
}
})
$form.Controls.AddRange(@($progress,$button))
$form.ShowDialog()
}
function Show-TabsDemo {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Demo Tabs"
$form.Size = "400,300"
$form.StartPosition = "CenterScreen"
$form.BackColor = "AliceBlue"
$tabs = New-Object System.Windows.Forms.TabControl
$tabs.Size = "350,200"
$tabs.Location = "20,20"
$tab1 = New-Object System.Windows.Forms.TabPage
$tab1.Text = "Pagina 1"
$tab1.BackColor = "WhiteSmoke"
$tab2 = New-Object System.Windows.Forms.TabPage
$tab2.Text = "Pagina 2"
$tab2.BackColor = "Beige"
$label1 = New-Object System.Windows.Forms.Label
$label1.Text = "Contenido de la pagina 1"
$label1.Location = "20,20"
$label2 = New-Object System.Windows.Forms.Label
$label2.Text = "Contenido de la pagina 2"
$label2.Location = "20,20"
$tab1.Controls.Add($label1)
$tab2.Controls.Add($label2)
$tabs.TabPages.AddRange(@($tab1,$tab2))
$form.Controls.Add($tabs)
$form.ShowDialog()
}
function Show-ToastDemo {
[System.Windows.Forms.MessageBox]::Show("Esto es una notificacion tipo Toast","Notificacion")
}
#===========================================================
# VENTANA PRINCIPAL
#===========================================================
$formMain = New-Object System.Windows.Forms.Form
$formMain.Text = "Super Demo GUI PowerShell"
$formMain.Size = "600,500"
$formMain.StartPosition = "CenterScreen"
$formMain.BackColor = "LightSteelBlue"
$menu = New-Object System.Windows.Forms.MenuStrip
$menuDemo = New-Object System.Windows.Forms.ToolStripMenuItem("Demos")
$menuDemo.DropDownItems.Add("TextBox y Boton", $null, { Show-TextBoxDemo })
$menuDemo.DropDownItems.Add("Slider", $null, { Show-SliderDemo })
$menuDemo.DropDownItems.Add("ListView", $null, { Show-ListViewDemo })
$menuDemo.DropDownItems.Add("Grid (DataGridView)", $null, { Show-GridDemo })
$menuDemo.DropDownItems.Add("ComboBox", $null, { Show-ComboDemo })
$menuDemo.DropDownItems.Add("CheckBox / RadioButton", $null, { Show-CheckRadioDemo })
$menuDemo.DropDownItems.Add("Calendario", $null, { Show-CalendarDemo })
$menuDemo.DropDownItems.Add("ProgressBar", $null, { Show-ProgressDemo })
$menuDemo.DropDownItems.Add("Tabs", $null, { Show-TabsDemo })
$menuDemo.DropDownItems.Add("Notificacion Toast", $null, { Show-ToastDemo })
$menu.Items.Add($menuDemo)
$formMain.MainMenuStrip = $menu
$formMain.Controls.Add($menu)
# LABEL GRANDE SIN ACENTOS
$labelTitulo = New-Object System.Windows.Forms.Label
$labelTitulo.Text = "DEMO - Seleccione una opcion del menu"
$labelTitulo.Font = New-Object System.Drawing.Font("Arial", 20, [System.Drawing.FontStyle]::Bold)
$labelTitulo.AutoSize = $true
$labelTitulo.ForeColor = "DarkBlue"
$labelTitulo.Location = "40,120"
$formMain.Controls.Add($labelTitulo)
$formMain.ShowDialog()
==================
saludos