如何在 PowerShell 中设置标签的背景透明? [英] How Can I set a label's background transparent in PowerShell?
问题描述
我在将 System.Winfows.Forms.Label
背景设置为透明时遇到问题.
I have problems to set a System.Winfows.Forms.Label
background to transparent.
在 C# 中很容易:
this.label1.BackColor = System.Drawing.Color.Transparent;
但是在我的 PowerShell GUI 中我无法获得相同的结果.我尝试了很多变体,但没有一个成功:
However in my PowerShell GUI I can't acchieve the same result. I tried many variants, but none worked out:
$my_label = New-Object System.Windows.Forms.Label
$my_label.BackColor = System.Drawing.Color.FromName("Transparent")
或
$my_color = New-Object System.Drawing.Color.Transparent
$my_label.BackColor = $my_color
在 C# 中,您可以超越这些样本,结果标签的背景将变得透明.然而,在 PowerShell 中,每次尝试都会导致不同的错误.
In C# you can overtake those samples and the resulting label's background becomes transparent. In PowerShell, however, every attempt resulted in different errors.
我是不是注意到了什么?
Haven't I paid regard to something?
推荐答案
您是否尝试过这种语法?
Have you tried this syntax?
$my_label.BackColor = [System.Drawing.Color]::FromName("Transparent")
对于像这样的静态方法,类的全名用括号括起来,然后是 2 个冒号,然后是方法名称和括号中的参数(与常规 PowerShell 方法不同).
For a static method such as this, the full name of the class surrounded by brackets, then 2 colons then the method name and parameters in parenthesis (unlike a regular PowerShell method).
这篇关于如何在 PowerShell 中设置标签的背景透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!