set a Powershell Data Entry to non Resizeable - powershell

I am programming Windows Powershell since 2 months and I haven't found anything about the resizeability of an input window. In Java there is something called 'setResizeable(true/false)' but I didn't find anything like that in the internet.
Thanks for your time and support :D

Set the FormBorderStyle property of the form to Sizable:
Add-type -AssemblyName System.Windows.Forms > $null
Add-Type -AssemblyName System.Drawing > $null
$Form = New-Object -TypeName System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size 250,400
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Sizable
$Form.ShowDialog()

Related

Trying to make a basic Ping tool with a simple GUI, However at the moment the ping button does nothing even though I've defined it to have an action

However at the moment the ping button does nothing even though I've defined it to have an action.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Data Entry Form'
$form.Size = New-Object System.Drawing.Size(400,400)
$form.StartPosition = 'CenterScreen'
$form = New-Object System.Windows.Forms.Form
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(35,35)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = "Ping"
$Button.Add_Click($Button_Click)
$Form.Controls.Add($Button)
$form.showdialog()
$Button_Click = $pinger
$pinger = Ping 8.8.8.8 -t > C:\Tools\Pingtoool.txt
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
If anyone could take a look and perhaps recommend better ways of doing things, I would gladly be all ears.
Thank you.
You just need to store your event as a scriptblock, in addition to this, the scriptblock should be defined before adding it to the Click event of your button. I have added a few modifications to your code, test it now :)
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Data Entry Form'
$form.Size = New-Object System.Drawing.Size(400,400)
$form.StartPosition = 'CenterScreen'
$form.Topmost = $true
$pingEvent = {
$file = New-TemporaryFile
Test-Connection 8.8.8.8 | Out-File $file
notepad.exe $file
}
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(35,35)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = "Ping"
$Button.Add_Click($pingEvent)
$Form.Controls.Add($Button)
$form.Add_Shown({$Button.Select()})
$result = $form.ShowDialog()
A few considerations:
ping -t would make your GUI freeze since it will run until being manually stopped.
ping has been changed for Test-Connection as it's PowerShell's built-in cmdlet intended for pinging.
$pinger = Ping 8.8.8.8 -t > C:\Tools\Pingtoool.txt is being executed at the moment this line is interpreted, if you want to execute this line when clicking the button you would store the code as a scriptblock:
$pinger = { Ping 8.8.8.8 -t > C:\Tools\Pingtoool.txt }
$Button.Add_Click($pinger)
It can be also simplified to:
$Button.Add_Click({
Ping 8.8.8.8 -t > C:\Tools\Pingtoool.txt
})
On line $Button.Add_Click($Button_Click), $Button_Click is being added as an event before being defined which is why when you click nothing happens (in addition to what was mentioned before, the event not being a scriptblock).

Embedding a font file (otf) into a Powershell forms script

I'm trying to embed a seven segment font into my script. So I tried to use the same way like embedding an icon for the forms title but it don't work. I think I need to use another command instead of [System.Drawing.Font] or am I completely wrong?
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$fontBase64 = 'T1RUTwAOAIAAAwBgQkFTRQAJAAQAACasAAAADkNGRiC5m9MSAAAH7AAAHbpGRlRNa6XwRAAAJrwAAAAcR0RFRgKxAqIAACWoAAAASkdQT1Ou773UAAAmLAAAAH5HU1VCRNhM5gAAJfQAAAA4T1MvMljUYiwAAAFQAAAAYGNtYXAxVzUsAAAFhAAAAkZoZWFkAmNATwAAAOwAAAA2aGhlYQdTAF8AAAEkAAAAJGhtdHgW0g5oAAAm2AAAAgZtYXhwAQFQAAAAAUgAAAAGbmFtZYoOx10AAAGwAAAD0nBvc3QAAAABAAAHzAAAACAAAQAAAAEAAOVWl1RfDzz1AAsD6AAAAADPuH6JAAAAAM+4fokAAP84A9EDIAACAAgAAgAAAAAAAAABAA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vAC8AQgAvAC4ALwAvAC8ALwAvAC8ALwAvAEIALwBCAFwBpwAvAC8ALwAvAC8ALwAvAC8BlgAvAC8ALwAvAC8ALwAvAEIALwAuAC8ALwAvAC8ALwAvAC8AAAGWAAAALwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEIAAAAAAAAAAAAvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC8ALwAAAAAAAAAAAAAAAAAAAC8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
$fontBytes = [Convert]::FromBase64String($fontBase64)
$stream = New-Object IO.MemoryStream($fontBytes, 0, $fontBytes.Length)
$stream.Write($fontBytes, 0, $fontBytes.Length);
$font = [System.Drawing.Font]::FromStream($stream, $true)
$Form = New-Object System.Windows.Forms.Form
$Form.SuspendLayout()
$Form.Size = "330,150"
$Form.AutoSize = $false
$Form.Text = "Font Test"
$Form.StartPosition = "CenterScreen"
$Label = New-Object System.Windows.Forms.Label
$Label.Location = "10,10"
$Label.Text = "123"
$Label.Font = New-Object System.Drawing.Font($font,12,[System.Drawing.FontStyle]::Regular)
$Form.Controls.Add($Label)
Thanks for help
As you have noticed, embedding a font in a form is not the same as embedding an icon to use as form icon.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$fontBase64 = 'T1RUTwAOAIAAAwBgQkFTRQAJAAQAACasAAAADkNGRiC5m9MSAAAH7AAAHbpGRlRNa6XwRAAAJrwAAAAcR0RFRgKxAqIAACWoAAAASkdQT1Ou773UAAAmLAAAAH5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AAAAEAAAAAAAAAAEAAAAAzD2izwAAAADPr89TAAAAAM+4fiECSQAAAkkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABpwBCAC8ALwAvAFwBpwAvAC8ALwBcAC8AXAIBAC8ALwGWAC8ALwBCAC4ALgBYAC8ALwBcAacALwAvAC8ALwAvAC8ALwAvAC8ALwAvAC8ALwGWAC8ALwAvAC8ALwAvAC8AQgAvAC4ALwAvAC8ALwAvAC8ALwAvAEIALwBCAFwBpwAvAC8ALwAvAC8ALwAvAC8BlgAvAC8ALwAvAC8ALwAvAEIALwAuAC8ALwAvAC8ALwAvAC8AAAGWAAAALwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEIAAAAAAAAAAAAvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC8ALwAAAAAAAAAAAAAAAAAAAC8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
$fontBytes = [Convert]::FromBase64String($fontBase64)
# create an unsafe memory block for the font data and get a pointer to it
$fontPtr = [System.Runtime.InteropServices.Marshal]::AllocCoTaskMem($fontBytes.Count)
# copy the bytes to that unsafe memory block
[System.Runtime.InteropServices.Marshal]::Copy($fontBytes, 0, $fontPtr, $fontBytes.Count)
# create a PrivateFontCollection object
$privateFonts = [System.Drawing.Text.PrivateFontCollection]::new()
# add the font to the font collection
$privateFonts.AddMemoryFont($fontPtr, $fontBytes.Count)
# free the unsafe memory block
[System.Runtime.InteropServices.Marshal]::FreeCoTaskMem($fontPtr)
# get the new font in a variable
$myFont = [System.Drawing.Font]::new($privateFonts.Families[0],12)
$Form = New-Object System.Windows.Forms.Form
$Form.Size = "330,150"
$Form.Text = "Font Test"
$Form.StartPosition = "CenterScreen"
$Label = New-Object System.Windows.Forms.Label
$Label.Location = "10,10"
$Label.AutoSize = $true
$Label.Text = "0123456789"
$Label.Font = $myFont
$Form.Controls.Add($Label)
$Form.ShowDialog()
# clean-up
$Form.Dispose()

How to allow Ctrl+A to select all in a Windows Form textbox (powershell)

I'm writing a .ps1 script with a windows forms GUI. When I run it from Powershell ISE, it allows the use of Ctrl+A to 'select all' in the text box. However when running the .ps1 outside of ISE, the action of CTRL+A does nothing.
Any idea what settings I can change on the text box to allow Ctrl+A?
The only threads I could find on this topic were for writing in other languages like C.
Currently what I have:
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(110,20)
$textbox.Add_KeyDown({
if ($_.KeyCode -eq "Enter") {$okButton.PerformClick()}
})
**$textbox.acceptstab = $true
$textbox.shortcutsenabled = $True**
$form.Controls.Add($textBox)
I can reproduce your issue here.
One option is to incorporate this answer - https://stackoverflow.com/a/29957334/3156906 - and call Application.EnableVisualStyles().
Your example then becomes (with an additional bit of set-up code to make it self-contained):
Add-Type -AssemblyName "System.Windows.Forms"
Add-Type -AssemblyName "System.Drawing"
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = new-object System.Windows.Forms.Form
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(110,20)
$textbox.Add_KeyDown({
if ($_.KeyCode -eq "Enter") {$okButton.PerformClick()}
})
#$textbox.acceptstab = $true
#$textbox.ShortcutsEnabled = $true
$form.Controls.Add($textBox)
$form.ShowDialog()
You can then use Ctrl+A in the textbox to select the text.
You could manually write the Ctrl+A event to select the textbox content:
$textbox.Add_KeyDown({
if (($_.Control) -and ($_.KeyCode -eq 'A')) {
$textbox.SelectAll()
}
})

Script runs with ISE but not powershell.exe

After months of "scripting" I finally got my script working as I need it to, except it only does what I want when running it from ISE. When I start it using powershell.exe it throws a fit something about unable to find [system.windows.forms. "dialogresult]".
I have attached the relevant portion of the script, TYIA
$cred = Get-Credential
$Job = Start-Job -ScriptBlock {
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Admin Tools’
$form.Size = New-Object System.Drawing.Size(900,600)
$form.StartPosition = 'CenterScreen'
$form.AutoSize = $true
$form.MaximizeBox = $false
$form.FormBorderStyle = 'FixedSingle'
$img = [System.Drawing.Image]::Fromfile("c:\users\$env:username\Pictures\logo.png")
$pictureBox = New-Object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width
$pictureBox.Height = $img.Size.Height
$pictureBox.Location = New-Object System.Drawing.Size(600,465)
$pictureBox.Image = $img
$form.controls.add($pictureBox)
$ADUCButton = New-Object System.Windows.Forms.Button
$ADUCButton.Location = New-Object System.Drawing.Point(10,25)
$ADUCButton.Size = New-Object System.Drawing.Size(300,100)
$ADUCButton.Font = New-Object System.Drawing.Font(“Times New Roman”,14, [System.Drawing.Fontstyle]::Bold)
$ADUCButton.Text = ' Active Directory Users and Computers '
$ADUCButton.Add_Click({Start-Process -filepath 'c:\windows\system32\cmd.exe' -WindowStyle maximized})
$ADUCButton.FlatAppearance.BorderColor = [System.Drawing.Color]::DarkBlue
$ADUCButton.BackColor = [System.Drawing.Color]::CornflowerBlue
$form.Controls.Add($ADUCButton)
$label = New-Object System.Windows.Forms.Label
$label.location = New-Object System.Drawing.Point(100,500)
$label.Size = New-Object System.Drawing.Size(280,70)
$label.Font = New-Object System.Drawing.Font("Lucida Console",8,
[System.Drawing.FontStyle]::Italic)
$label.Text = 'Created by a PowerShell Novice'
$form.Controls.Add($label)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(850,300)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Close'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $listBox.SelectedItems
$x
}
} -Credential $cred
Recieve-Job $job
Any assistance you can provide is greatly appreciated.
When you are in the ISE it will autoload modules needed to do many things, the consoelhost does not.
If you have form code in your scripts, you must at needed resources, for it to properly run in the consolehost.
Put this at the top of your script. Here is a snippet I keep in for functions
# Initialize GUI resources
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName presentationframework
Add-type -AssemblyName microsoft.VisualBasic
[System.Windows.Forms.Application]::EnableVisualStyles()
Add-Type -AssemblyName System.Drawing
# Required for use with web SSL sites
[Net.ServicePointManager]::
SecurityProtocol = [Net.ServicePointManager]::
SecurityProtocol -bor
[Net.SecurityProtocolType]::
Tls12
You don't need them all, depending on what you are doing or plan to. At the minimum, you need this...
Add-Type -AssemblyName System.Windows.Forms
BTW, this is probably a posting error, but this line is not syntactically correct.
if ($result -eq [System.Windows.Forms.DialogResult}::OK)
It should be this...
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
Open/Close bracket type must match

Graphic Interface in Powershell looks different in PowerGUI

My first question here, sorry if something is wrong in the way I posted.
Well, I'm new in developing graphic things in Powershell, and I needed to make a simple script to configure hostname, IP, etc and make it simple to end users (ugh).
I'm developing a simple graphic interface in PowerGUI, I'm on it for a couple of days, testing it exclusively inside PowerGUI, and it was not looking bad, but when I finally ran the script outside PowerGUI, just running it in Powershell, the graphics looks quite different than in PowerGUI, like positioning, borders, themes, etc. I was disappointing. I'll post screenshots and a bit of the code.
Inside PowerGUI
Outside
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0
ipconfig -all | Out-File $env:SYSTEMDRIVE"\old_network.txt"
#INICIO Fontes da aplicação
$font = New-Object System.Drawing.Font("Segoe UI",8.5,[System.Drawing.FontStyle]::Regular)
$font_btn_concluir = New-Object System.Drawing.Font("Segoe UI",15,[System.Drawing.FontStyle]::Regular)
$font_l_instru = New-Object System.Drawing.Font("Segoe UI",12,[System.Drawing.FontStyle]::Regular)
$font_i_n_sala = New-Object System.Drawing.Font("Segoe UI",20,[System.Drawing.FontStyle]::Regular)
#FIM Fontes da aplicação
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size #(800,600)
$form.StartPosition = "CenterScreen"
$form.Font = $font
#$form.ControlBox = $false
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.Text = "Configuração Telesalas - UNIASSELVI"
$form.Icon = $icon
$form.FormBorderStyle = "FixedDialog
So, anyone have any clue why this happens?
Its Because of the version of your forms. powergui automatically call v4.0** form my system but powershell consol calls v2. you can test it by yourself after compiling check the consols.