标签控制Powershell的梯度背景

时间:2016-02-09 17:56:04

标签: winforms powershell background gradient

我正在尝试在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)
    })

感谢您的帮助!

1 个答案:

答案 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)))
    })