Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom ToolStripControlHost property problem with FlatButtonAppearance

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
Just recently I leaned how to create custom ToolStripControlHosts so I could have custom items on StatusStrips. Once I got the basics down it has worked great until now. Neither a splitbutton nor a dropdown button look or act corrctly so I create just a button. The problem I have is I can't seem to get the FlatButtonAppearance properties to work.

Here is the last code I've tried:
Code:
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Drawing

<System.ComponentModel.DesignerCategory("code")> _
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)> _
Public Class ToolStripStatusButton
    Inherits Windows.Forms.ToolStripControlHost

    Enum FlatStyles
        Flat = 0
        Popup = 1
        Standard = 2
        System = 3
        ToolStripStandard = 4
    End Enum


    Private _FlatButton As FlatButtonAppearance
    Private _ButtonFlatStyle As FlatStyles

    Public Sub New()
        MyBase.New(New Windows.Forms.Button)
        'CType(Control, Windows.Forms.Button).FlatAppearance.BorderSize = 0
    End Sub

    <System.ComponentModel.Browsable(False)> _
    Public ReadOnly Property ButtonControl() As Windows.Forms.Button
        Get
            Return CType(Control, Windows.Forms.Button)
        End Get
    End Property

    'Blue is just a test to see if it actually worked.
    <System.ComponentModel.DefaultValue(GetType(System.Windows.Forms.FlatButtonAppearance), "Color.Blue, 0, Color.Blue, Color.Blue, Color.Blue")> _
    Public Property ButtonFlatAppearance() As FlatButtonAppearance
        Get
            Return ButtonControl.FlatAppearance
        End Get
        Set(ByVal value As FlatButtonAppearance)
            '_FlatButton = value

            ButtonControl.FlatAppearance.BorderColor = value.BorderColor
            ButtonControl.FlatAppearance.BorderSize = value.BorderSize
            ButtonControl.FlatAppearance.CheckedBackColor = value.CheckedBackColor
            ButtonControl.FlatAppearance.MouseDownBackColor = value.MouseDownBackColor
            ButtonControl.FlatAppearance.MouseOverBackColor = value.MouseOverBackColor
        End Set
    End Property

    <System.ComponentModel.DefaultValue(4)> _
    Public Property ButtonFlatStyle() As FlatStyles
        Get
            Return _ButtonFlatStyle
        End Get
        Set(ByVal value As FlatStyles)
            _ButtonFlatStyle = value

            Select Case value
                Case FlatStyles.ToolStripStandard
                    ButtonControl.FlatStyle = FlatStyle.Flat
                Case FlatStyles.Flat
                    ButtonControl.FlatStyle = FlatStyle.Flat
                Case FlatStyles.Popup
                    ButtonControl.FlatStyle = FlatStyle.Popup
                Case FlatStyles.Standard
                    ButtonControl.FlatStyle = FlatStyle.Standard
                Case FlatStyles.System
                    ButtonControl.FlatStyle = FlatStyle.System
            End Select
        End Set
    End Property

    Protected Overrides Sub OnSubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnSubscribeControlEvents(control)

        Dim clickButtonControl As Button = CType(control, Button)
        AddHandler clickButtonControl.Click, AddressOf ButtonControl_Click
        AddHandler clickButtonControl.MouseEnter, AddressOf ButtonControl_MouseEnter
        AddHandler clickButtonControl.MouseLeave, AddressOf ButtonControl_MouseLeave
    End Sub

    Protected Overrides Sub OnUnsubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnUnsubscribeControlEvents(control)

        Dim clickButtonControl As Button = CType(control, Button)
        RemoveHandler clickButtonControl.Click, AddressOf ButtonControl_Click
    End Sub

    Public Event ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
    Private Sub ButtonControl_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent ButtonClick(sender, e)
    End Sub

    Private Sub ButtonControl_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)
        If _ButtonFlatStyle = FlatStyles.ToolStripStandard Then ButtonControl.FlatStyle = FlatStyle.Popup
    End Sub

    Private Sub ButtonControl_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
        If _ButtonFlatStyle = FlatStyles.ToolStripStandard Then ButtonControl.FlatStyle = FlatStyle.Flat
    End Sub
End Class
I've tried with/without DefaultValues for the property. No matter what I set in designer the Values it actually uses are the actual default values for FlatButtonAppearance class.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top