I want to set a transparent background in a NET form created by a powershell script:
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Location = New-Object System.Drawing.Point(0, 0);
$Form.StartPosition = "manual"
$Form.AutoSize = $true;
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
$Form.Text = "Sample Form"
$Font = New-Object System.Drawing.Font("Times New Roman",18,[System.Drawing.FontStyle]::Italic)
$Form.Font = $Font
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "This form is very simple."
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.ShowDialog()
pause
I would like to set the background color as transparent so I should add:
$Form.BackColor = [System.Drawing.Color]::FromName("Transparent")
But, of course, this throws an error about that "The control doesn't allow transparent background colors". This is because (I think?) I should use setStyle with the SupportsTransparentBackColor and UserPaint but I don't know how to set its style... I thought something like this:
$Form.SetStyle([System.Windows.Forms]::SupportsTransparentBackColor, true)
#or
$Form.SetStyle([System.Windows.Forms]::SupportsTransparentBackColor, $true)
#or
$Form.SetStyle= ([System.Windows.Forms]::SupportsTransparentBackColor, true)
#or
$Form.SetStyle= ([System.Windows.Forms]::SupportsTransparentBackColor, $true)
but It says that SetStyle doesn't exist for $Form. How am I supposed to correctly enable transparent background? By the way I already saw these posts\sources: 1st; 2nd; 3rd; 4th; 5th;
I don't want to use "TransparencyKey" becuse it leaves the label with some colored borders...
EDIT 17/03/2019
@postanote has linked two posts where I found that i could use:
$Form.AllowTransparency = $true
#and (but it doesn' work)
$Form.WindowStyle = $true
I also found that with $Form | Format-List -Property *
I could retrive all properties of the form, and I couldn't see anything like WindowStyle or SetStyle...