我正在尝试在powershell中为我的标签控件创建渐变背景。我能够创建渐变背景,但控件的文本由渐变覆盖。这就是我到目前为止所做的:
$label = new-object system.windows.forms.label
$label.text = "hello"
$label.forecolor = "white"
$label.add_paint({$brush = new-object System.Drawing.Drawing2D.LinearGradientBrush((new-object system.drawing.point 0,0),(new-object system.drawing.point($this.clientrectangle.width,$this.clientrectangle.height)),"black","white")
$_.graphics.fillrectangle($brush,$this.clientrectangle)
})
感谢您的帮助!
答案 0 :(得分:1)
Draw A Gradient On A Label Control来自我关于Microsoft
上的脚本表单的问题我怀疑我用我的图形覆盖了我的标签,所以我需要使用抽绳方法在我为渐变创建的图形上写字。
$label = new-object system.windows.forms.label
$label.text = "hello"
$label.forecolor = "white"
$label.add_paint({$brush = new-object System.Drawing.Drawing2D.LinearGradientBrush((new-object system.drawing.point 0,0),(new-object system.drawing.point($this.clientrectangle.width,$this.clientrectangle.height)),"black","white")
$_.graphics.fillrectangle($brush,$this.clientrectangle)
$brush2 = new-object System.Drawing.Drawing2D.LinearGradientBrush((new-object system.drawing.point 0,0),(new-object system.drawing.point($this.clientrectangle.width,$this.clientrectangle.height)),"white","black")
$_.graphics.drawstring("hello",(new-object System.Drawing.Font("times new roman",18,[System.Drawing.FontStyle]::regular)),$brush2,(new-object system.drawing.pointf(20,0)))
})