2009-06-23 56 views

回答

0

您需要創建自己的ToolStripRenderer,並在代碼中繪製按鈕。採用這種方法,您可以模擬任何形狀,並且幾乎可以模擬任何形狀。

然後,自定義渲染器完成後,您將需要將您的渲染器分配給tooltrip,就是這樣。

描述寫入自定義渲染器的article

更新:您還可以檢查this article,它可以爲您的任務有用。

+0

嗨,謝謝。我已經完成了。按鈕的形狀可以有不同的繪製方式,但在工具條上,它總是佔據一個矩形區域。我將在上面編輯以提供當前圖像。 – bperreault 2009-06-23 15:03:36

+0

嗨 感謝您的第二個鏈接,這很有趣。我看到它是如何做到的。 – bperreault 2009-06-23 17:38:10

0

我想這是可能的,在仲裁員的帖子看到第二個鏈接後,但我會保持我的解決方案。由於時間限制,時間很短,我已將控制類型更改爲普通按鈕。在這裏,我可以設置區域,並通過將區域設置爲我稱之爲人字形路徑的方式來重現所需的外觀。最上面的兩個按鈕是從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 Function