2011-03-22 143 views

回答

4

看看这个great page。文章中的代码是用C#编写的。下面是代码you'e兴趣和更新的矩形填充的vb.net端口:(基于制品的三角形填充样品)

Dim pgb As New PathGradientBrush(New Point() { _ 
     New Point(0, 0), _ 
     New Point(0, Me.ClientRectangle.Height), _ 
     New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height), _ 
     New Point(Me.ClientRectangle.Width, 0)}) 
pgb.SurroundColors = New Color() {Color.Red} 
pgb.CenterColor = Color.Gray 
e.Graphics.FillRectangle(pgb, Me.ClientRectangle) 
pgb.Dispose() 

下面是另一个可能的解决方案:

Dim pth As New GraphicsPath() 
pth.AddEllipse(Me.ClientRectangle) 
Dim pgb As New PathGradientBrush(pth) 
pgb.SurroundColors = New Color() {Color.Red} 
pgb.CenterColor = Color.Gray 
e.Graphics.FillRectangle(pgb, Me.ClientRectangle) 

请注意,最后一段代码将绘制一个矩形内的圆。如果你想让圆形渐变填充整个矩形,你必须计算一个更大的椭圆形路径和更大的矩形。

+0

这是一些很酷的东西,谢谢!最后一段特别有用。 – 2011-03-22 15:03:35

+1

一些有用的窍门:1.不是将椭圆放大,而是将矩形放大,保持椭圆大小相同,并在其后面绘制椭圆外部颜色的矩形。 2.如果不是白色,当内部颜色是外部颜色的阴影时,内部颜色往往看起来更好。 – 2011-03-23 21:15:31

+0

谢谢橡树。这是很好的信息。漂亮的平面设计提示呢! – 2011-03-23 22:55:49