2014-09-03 31 views
3

我想在標題欄添加一個按鈕,我想給它比其他按鍵相同方面,但我無法做到這一點,請參閱:Telerik,如何在RadForm TitleBar中正確添加RadButtonElement?

enter image description here

通知我新按鈕的顏色比其他顏色更亮,並且尺寸也會突出黃色邊框。

這是我使用的代碼:

Imports Telerik.WinControls.UI 

Public Class RadForm_TestForm : Inherits RadForm 

Public Sub New() 

    ' This call is required by the designer. 
    InitializeComponent() 

    ' Set the RadForm design. 
    With Me 

     .ThemeName = "VisualStudio2012Dark" ' The visual theme. 
     .FormElement.Border.ForeColor = Color.Gold ' Set the borders color. 
     .FormElement.Border.Width = 1I ' Set the borders width. 
     .FormElement.TitleBar.BorderPrimitive.ForeColor = Color.Red 
     .FormElement.TitleBar.ForeColor = Color.LightGray ' Set the TitleBar text color. 
     .FormElement.TitleBar.MinimizeButton.Enabled = False 

    End With 

    ' Create a RadButtonElement. 
    Dim SystrayButton As New RadButtonElement() 
    With SystrayButton ' Set the RadForm design. 

     .Text = "." 
     .ShowBorder = False 
     .AutoSize = False 

     .Size = Me.FormElement.TitleBar.MinimizeButton.Size 
     ' .ButtonFillElement.BackColor = Me.FormElement.TitleBar.MinimizeButton.BackColor 

    End With 

    ' Add the Button in the TitleBar. 
    Me.FormElement.TitleBar.Children(2).Children(0).Children.Insert(0, SystrayButton) 

End Sub 

End Class 

注意,在上面這行代碼被禁用:

.ButtonFillElement.BackColor = Me.FormElement.TitleBar.MinimizeButton.BackColor 

因爲如果我改變顏色以這種方式,如果我把鼠標放在按鈕上,它在聚焦時不會改變顏色。

更新:

可能的解決方案可以在RadButtonElement應用的我RadForm同樣的主題?

我讀過這樣的:http://www.telerik.com/forums/apply-theme-to-radbuttonelement

...但我真的不知道如何做到這一點,我沒有任何「DefaultStyleBuilder」,我無法找到有關Telerik的信息是什麼意思是。

+0

參見[Vista的Aero的ToolStrip對非客戶區(http://www.codeproject.com/Articles/32623/Vista-Aero-ToolStrip-on-Non-Client-Area)[vb.net](http://www.codeproject.com/Articles/44235/Painting-Vista-s-Aero-NonClientArea-in-VB-淨)。 – 2014-09-09 19:46:56

+0

請參見[如何使用Windows窗體在窗口標題欄中繪製自定義按鈕](http://stackoverflow.com/a/107437/3453226)。 – 2014-09-09 19:51:18

+0

@Joiner謝謝,但你理解我的問題的根源?,是不是我正在尋找的解決方案,我已經在使用一個用戶控件,它不需要破解表單並與客戶端/客戶區添加一個按鈕。這是Telerik UI。 – ElektroStudios 2014-09-10 13:35:16

回答

0

Teler建議的解決方案ik論壇:

FormElement.TitleBar.SystemButtons集合包含RadImageButtonElements。爲了添加一個新的系統按鈕到標題欄,你應該創建一個RadImageButtonElement。此外,要獲得與最小化按鈕相同的設計,您應該將RadImageButtonElement.ThemeRole屬性設置爲「TitleBarMinimizeButton」。之後,將DisplayStyle屬性更改爲文本。下面是一個示例代碼段:

Sub New() 
    InitializeComponent() 

    With Me 
     .ThemeName = "VisualStudio2012Dark" ' The visual theme. 
     .FormElement.Border.ForeColor = Color.Gold ' Set the borders color. 
     .FormElement.Border.Width = 1I ' Set the borders width. 
     .FormElement.TitleBar.BorderPrimitive.ForeColor = Color.Red 
     .FormElement.TitleBar.ForeColor = Color.LightGray ' Set the TitleBar text color. 
     .FormElement.TitleBar.MinimizeButton.Enabled = False 
    End With 

    ' Create a RadButtonElement. 
    Dim systrayButton As New RadImageButtonElement() 
    With systrayButton ' Set the RadForm design. 
     .ThemeRole = "TitleBarMinimizeButton" 
     .Text = "." 
     .DisplayStyle = Telerik.WinControls.DisplayStyle.Text 
     .ShowBorder = False 
     .AutoSize = False 
     .Size = Me.FormElement.TitleBar.MinimizeButton.Size 
    End With 
    AddHandler systrayButton.Click, AddressOf systrayButton_Click 
    ' Add the Button in the TitleBar. 
    Me.FormElement.TitleBar.SystemButtons.Children.Insert(0, systrayButton) 
End Sub 

Private Sub systrayButton_Click(sender As Object, e As EventArgs) 
    Me.Size = New Size(600, 600) 
End Sub 

enter image description here

來源:http://www.telerik.com/forums/how-to-properly-add-a-radbuttonelement-in-a-radform-titlebar

2

+1我看到了這個難題。

如果要在標題欄中使用按鈕的懸停狀態,按下狀態和正常狀態,則需要創建三個圖像並將其應用於鼠標事件,即在MouseEnter上應用懸停圖像,在MouseLeave上應用正常圖像,以及在MouseDown上按下的圖像。

我看到按鈕是如何與黃線稍微重疊的,因此您可能需要使用圖像來解決此問題。

像你說的設置RadButton BackColors會阻止默認的懸停,按下和正常狀態行爲。

它看起來像你這樣做是正確的 - 一個細微的變化是使用TitleBar.SystemButtons而不是穿越繼承TitleBar.Children(2).Children(0).Children.

這裏是你如何能做到這一點:

RadButtonElement btn = new RadButtonElement(); 
btn.ShowBorder = false; 
btn.Image = Resources.NormalState; 
this.FormElement.TitleBar.SystemButtons.Children.Insert(0,btn); 

PS我不認爲使用'StyleBuilders'可以讓你達到你所看到的效果,並且這個請求已經被Telerik建議:http://feedback.telerik.com/Project/154/Feedback/Details/109772-add-helpbutton-at-the-titlebar-of-radform

+0

感謝您的幫助,但後來只是爲了能夠在Telerik窗體的Telerik標題欄上添加一個新的Telerik按鈕(是的,我想要說Telerik這個詞是因爲telerik所做的所有這些都是不正常的,終端用戶在telerik Form標題欄中添加了一個telerik按鈕,該按鈕的外觀與其他人不一樣)。我需要深入到像Photoshop這樣的imagedesign知識來爲按鈕設計3個圖像嗎?是的,它很容易繪製一個正方形,並填充相同的主題顏色,但我的意思是Telerik UI旨在與開發人員,而不是設計人員使用 – ElektroStudios 2014-09-12 12:32:28

+0

此外,如果開發人員使用Telerik UI for Winforms標題欄中的按鈕是否需要添加主題選擇器以讓該應用程序的用戶更改UI主題?我需要設計+/- 30個不同的圖像?如果我的文字的前景顏色發生了什麼改變它呢?...更多圖片來設計?我真的希望我對這個問題一無所知,Telerik提供了一個官方解決方案,如:「設置此屬性以調整按鈕的方面,就像標題欄中的其他按鈕一樣」,「因爲這是不正常的。再次感謝您的回答! – ElektroStudios 2014-09-12 12:33:10

+0

+50爲你和我做了另一個賞金,希望找到這個問題的關鍵,因爲我不能接受像你所建議的那樣的替代方案,爲每個案例設計大量圖像的工作只是不專注於軟件開發人員,如果我們正在討論大量圖像,這有點瘋狂。謝謝 – ElektroStudios 2014-09-12 12:40:08