title: powershell NET Form set transparent background
body: <p>I want to set a transparent background in a NET form created by a powershell script:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I would like to set the background color as transparent so I should add:</p>
  
  <pre><code>$Form.BackColor = [System.Drawing.Color]::FromName("Transparent")
  </code></pre>
  
  <p>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 <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.setstyle?view=netframework-4.7.2" rel="nofollow noreferrer">setStyle</a> with the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.controlstyles?view=netframework-4.7.2#System_Windows_Forms_ControlStyles_SupportsTransparentBackColor" rel="nofollow noreferrer">SupportsTransparentBackColor</a> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.controlstyles?view=netframework-4.7.2#System_Windows_Forms_ControlStyles_UserPaint" rel="nofollow noreferrer">UserPaint</a> but I don't know how to set its style... I thought something like this:</p>
  
  <pre><code>$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)
  </code></pre>
  
  <p>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: <a href="https://stackoverflow.com/questions/14925409/transparent-background-on-form">1st</a>; <a href="https://stackoverflow.com/questions/4387680/transparent-background-on-winforms">2nd</a>; <a href="https://stackoverflow.com/questions/6638517/make-a-forms-background-transparent">3rd</a>; <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control?view=netframework-4.7.2" rel="nofollow noreferrer">4th</a>; <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.setstyle?view=netframework-4.7.2" rel="nofollow noreferrer">5th</a>;<br>
  I don't want to use "TransparencyKey" becuse it leaves the label with some colored borders...<br>
  <strong>EDIT 17/03/2019</strong><br>
  <a href="http://stackoverflow.com/users/9132707/">@postanote</a> has linked two posts where I found that i could use:</p>
  
  <pre><code>$Form.AllowTransparency = $true
  #and (but it doesn' work)
  $Form.WindowStyle = $true
  </code></pre>
  
  <p>I also found that with <code>$Form | Format-List -Property *</code> I could retrive all properties of the form, and I couldn't see anything like WindowStyle or SetStyle...</p>