gokul krishnan
gokul krishnan

Reputation: 1

How to set radius for textbox and button in PowerShell studio?

I'm doing a simple project in PowerShell studio. I want my textbox and button in round shapes, how do I do that in both programmatically or using the properties window

Upvotes: 0

Views: 861

Answers (2)

Santiago Squarzon
Santiago Squarzon

Reputation: 60145

No idea if this is the right way to approach this on PowerShell, just tried to translate the C# code from Round shaped buttons.

Hopefully it helps you to start your research.

Demo

gifdemo

Code

Add-Type -AssemblyName System.Windows.Forms, System.Drawing
[void][System.Windows.Forms.Application]::EnableVisualStyles()

$bounds = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea

$mainForm = [System.Windows.Forms.Form]::new()
$mainForm.StartPosition = 'CenterScreen'
$mainForm.Size = [System.Drawing.Size]::new(($bounds.Width/3),($bounds.Height/3))
$mainForm.FormBorderStyle = 'Sizable'
$mainForm.Text = 'Circle Button'
$mainForm.WindowState = 'Normal'
$mainForm.KeyPreview = $True

$mainForm.Add_Resize({
    $circleBtn.Width = $mainForm.Width-100
    $circleBtn.Height = $mainForm.Height-100
    $path = [System.Drawing.Drawing2D.GraphicsPath]::new()
    $path.AddEllipse(0, 0, $circleBtn.ClientSize.Width, $circleBtn.ClientSize.Height)
    $circleBtn.Region = [System.Drawing.Region]::new($path)
})

$circleBtn = [System.Windows.Forms.Button]::new()
$circleBtn.Text = '&Hello'
$circleBtn.Font = [System.Drawing.Font]::new('Calibri',30)
$circleBtn.Width = $mainForm.Width-100
$circleBtn.Height = $mainForm.Height-100
$circleBtn.Location = [System.Drawing.Size]::new(40,20)
$circleBtn.FlatAppearance.BorderSize = 0
$circleBtn.FlatStyle = 'Flat'
$circleBtn.BackColor = [System.Drawing.Color]::LightGray
$circleBtn.Add_MouseHover({
    $this.BackColor = [System.Drawing.Color]::DarkGray
})

$circleBtn.Add_MouseLeave({
    $this.BackColor = [System.Drawing.Color]::LightGray
})
$path = [System.Drawing.Drawing2D.GraphicsPath]::new()
$path.AddEllipse(0, 0, $circleBtn.ClientSize.Width, $circleBtn.ClientSize.Height)
$circleBtn.Region = [System.Drawing.Region]::new($path)
$mainForm.Controls.Add($circleBtn)

$mainForm.Add_Shown({$this.Activate()})
$mainForm.ShowDialog()

Upvotes: 1

alexzelaya
alexzelaya

Reputation: 255

If it's an image you want:

$button.Image=[System.Drawing.Image]::FromFile('c:\image.jpg')

If you want to round it out, it is not possible with PowerShell Studio.

Upvotes: 0

Related Questions