在Winforms中有没有办法改变ToolStrip项的形状?如果它是一个面板,我可以将区域设置为我的GraphicPath对象。但是对于ToolStripItem,我不知道该怎么做,因为它不是从控件派生出来的。alt text http://store.ezburn.com/images/productimages/toolstripbuttonshapes.jpg
发布于 2009-06-23 14:56:16
您需要创建自己的ToolStripRenderer,并在代码中绘制按钮。使用这种方法,您可以模拟任何形状,通常情况下,几乎可以模拟任何形状。
然后自定义渲染器完成后,您将需要分配您的渲染器到toolstrip,这就是它。
描述编写自定义渲染器的article。
更新:你也可以查看this article,它对你的任务很有用。
发布于 2009-06-23 15:40:55
我猜这是可能的,在看到仲裁者的帖子中的第二个链接后,但我将保留我的解决方案。由于截止日期的原因,时间很短,我已经将控件类型更改为普通按钮。在这里,我可以设置区域,并且可以通过将区域设置为我所称的人字形路径来重现所需的外观。顶部的两个按钮是从带有自定义绘制和区域集的Windows.Forms.Button派生的。底部的两个按钮是带有自定义渲染器和自定义绘画的工具条按钮。
alt text http://store.ezburn.com/images/productimages/toolstripbuttonshapes-final.jpg
我不知道这是否会对任何人有帮助。但下面是我用来设置区域的代码:
Private Sub setRegion()
Dim r As Rectangle = ClientRectangle
Me.Region = New Region(getChevronPath(r.X, r.Y, r.Width, r.Height))
End Sub
Private Function getChevronPath(ByVal X As Single, ByVal Y As Single, _
ByVal width As Single, ByVal height As Single) As GraphicsPath
Dim w As Integer = Convert.ToInt32(X + width - ChevronHeight)
Dim hh As Integer = Convert.ToInt32(height / 2)
Dim gp As New GraphicsPath()
'top
gp.AddLine(X, Y, w, Y)
'arrowtop, on the right
gp.AddLine(w, Y, w + ChevronHeight, hh)
'arrowbottom, on the right
gp.AddLine(w + ChevronHeight, hh, w, Y + height)
'bottom
gp.AddLine(w, Y + height, X, Y + height)
If EndButton Then
'left
gp.AddLine(X, Y + height, X, Y)
Else
'arrowbottom, on the left
gp.AddLine(X, Y + height, ChevronHeight, hh)
'arrowtop on the left
gp.AddLine(ChevronHeight, hh, X, Y)
End If
gp.CloseFigure()
Return gp
End Functionhttps://stackoverflow.com/questions/1032966
复制相似问题