Click here to Skip to main content
15,896,730 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How do I run a song on vb ? Pin
Dave Kreskowiak12-Feb-15 5:11
mveDave Kreskowiak12-Feb-15 5:11 
GeneralRe: How do I run a song on vb ? Pin
Member 1144766212-Feb-15 5:15
Member 1144766212-Feb-15 5:15 
GeneralRe: How do I run a song on vb ? Pin
Dave Kreskowiak12-Feb-15 5:52
mveDave Kreskowiak12-Feb-15 5:52 
Questionvb code for speech? Pin
Member 1144760612-Feb-15 4:09
Member 1144760612-Feb-15 4:09 
AnswerRe: vb code for speech? Pin
Eddy Vluggen12-Feb-15 5:37
professionalEddy Vluggen12-Feb-15 5:37 
AnswerRe: vb code for speech? Pin
Member 1144787312-Feb-15 5:59
Member 1144787312-Feb-15 5:59 
AnswerRe: vb code for speech? Pin
Chris Quinn13-Feb-15 0:30
Chris Quinn13-Feb-15 0:30 
QuestionOwner drawn ComboBox issues. Pin
D.VanKeuren11-Feb-15 11:35
D.VanKeuren11-Feb-15 11:35 
I have been banging my head on this for several days now.  I wanted to have a better looking flat combobox and be able to change the button color.  I also wanted to remove the highlighting that occurs after an item is selected.  What I came up with works, until visual styles is enabled.  When visual styles are enabled, the text in the textbox area of the combobox either gets painted over, or not drawn at all.  I could disable visual styles, but I would rather not have to do that as it just seem like a band-aid to fix an issue that I feel should not be happening.  I tried disabling visual styles using SetWindowTheme, but that does not seem to work.  I was hoping someone out there might notice what I am doing wrong.

Here is the code:

VB.NET
Public Class UMSComboBox : Inherits ComboBox

    Friend Declare Unicode Function SetWindowTheme Lib "UxTheme.dll" _
     (ByVal hwnd As IntPtr, _
     ByVal pszSubAppName As String, _
     ByVal pszSubIdList As String) As Integer

    Public Property ButtonColor() As Color
        Get
            Return _ButtonColor
        End Get
        Set(ByVal Value As Color)
            _ButtonColor = Value
            Me.Invalidate()
        End Set
    End Property
    Private _ButtonColor As Color = SystemColors.Control

    Public Property HighlightColor() As Color
        Get
            Return _HighlightColor
        End Get
        Set(ByVal Value As Color)
            _HighlightColor = Value
            Me.Invalidate()
        End Set
    End Property
    Private _HighlightColor As Color = SystemColors.Highlight

    Public Sub New()
        MyBase.New()
        Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        'SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.ResizeRedraw, True)
        SetStyle(ControlStyles.Selectable, True)
        SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        SetStyle(ControlStyles.UserPaint, True)
    End Sub


    Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)

        Dim g As Graphics = e.Graphics
        g.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
        ControlPaint.DrawBorder(g, Me.ClientRectangle, Me.ForeColor, ButtonBorderStyle.Solid)

        'Draw the background of the dropdown button
        Dim rect As Rectangle = New Rectangle(Me.Width - 12, 0, 12, Me.Height)
        g.FillRectangle(New SolidBrush(_ButtonColor), rect)
        ControlPaint.DrawBorder(g, rect, Me.ForeColor, ButtonBorderStyle.Solid)

        'Create the path for the arrow
        Dim pth As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath()
        Dim TopLeft As PointF = New PointF(Me.Width - 10, CSng((Me.Height - 5) / 2))
        Dim TopRight As PointF = New PointF(Me.Width - 3, CSng((Me.Height - 5) / 2))
        Dim Bottom As PointF = New PointF(Me.Width - 6, CSng((Me.Height + 2) / 2))
        pth.AddLine(TopLeft, TopRight)
        pth.AddLine(TopRight, Bottom)

        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

        'Draw the arrow
        g.FillPath(New SolidBrush(Me.ForeColor), pth)
        'If Me.DroppedDown Then
        '    g.FillPath(New SolidBrush(SystemColors.HighlightText), pth)
        'Else
        '    g.FillPath(New SolidBrush(SystemColors.ControlText), pth)
        'End If

    End Sub

    Protected Overrides Sub OnDrawItem(e As System.Windows.Forms.DrawItemEventArgs)
        If e.Index < 0 Then Exit Sub
        Dim rect As Rectangle = e.Bounds
        If Me.DroppedDown Then
            If CBool(e.State And DrawItemState.Selected) Then
                e.Graphics.FillRectangle(New SolidBrush(_HighlightColor), rect) 'change the selected color you like
            Else
                e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), rect)
            End If
        Else
            e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), rect)
        End If
        Dim itemtext As String = Me.Items(e.Index).ToString
        Dim b As New SolidBrush(Me.ForeColor)
        e.Graphics.DrawString(itemtext, e.Font, b, e.Bounds, StringFormat.GenericDefault)
    End Sub

    Protected Overrides Sub OnHandleCreated(e As System.EventArgs)
        MyBase.OnHandleCreated(e)
        Me.FlatStyle = Windows.Forms.FlatStyle.System
        SetWindowTheme(Me.Handle, String.Empty, "COMBOBOX")
    End Sub

End Class

QuestionHow to detect a mouse click outside a focused control Pin
dilkonika9-Feb-15 18:22
dilkonika9-Feb-15 18:22 
AnswerRe: How to detect a mouse click outside a focused control Pin
Richard MacCutchan9-Feb-15 22:20
mveRichard MacCutchan9-Feb-15 22:20 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 4:06
dilkonika10-Feb-15 4:06 
AnswerRe: How to detect a mouse click outside a focused control Pin
Richard Andrew x6410-Feb-15 4:58
professionalRichard Andrew x6410-Feb-15 4:58 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 5:03
dilkonika10-Feb-15 5:03 
AnswerRe: How to detect a mouse click outside a focused control Pin
Richard Andrew x6410-Feb-15 5:06
professionalRichard Andrew x6410-Feb-15 5:06 
GeneralRe: How to detect a mouse click outside a focused control Pin
Kenneth Haugland10-Feb-15 7:10
mvaKenneth Haugland10-Feb-15 7:10 
GeneralRe: How to detect a mouse click outside a focused control Pin
Richard MacCutchan10-Feb-15 5:06
mveRichard MacCutchan10-Feb-15 5:06 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 5:08
dilkonika10-Feb-15 5:08 
GeneralRe: How to detect a mouse click outside a focused control Pin
Richard MacCutchan10-Feb-15 5:16
mveRichard MacCutchan10-Feb-15 5:16 
GeneralRe: How to detect a mouse click outside a focused control Pin
Eddy Vluggen10-Feb-15 5:20
professionalEddy Vluggen10-Feb-15 5:20 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 6:22
dilkonika10-Feb-15 6:22 
GeneralRe: How to detect a mouse click outside a focused control Pin
Eddy Vluggen10-Feb-15 7:40
professionalEddy Vluggen10-Feb-15 7:40 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 9:33
dilkonika10-Feb-15 9:33 
GeneralRe: How to detect a mouse click outside a focused control Pin
Eddy Vluggen10-Feb-15 11:21
professionalEddy Vluggen10-Feb-15 11:21 
GeneralRe: How to detect a mouse click outside a focused control Pin
dilkonika10-Feb-15 18:23
dilkonika10-Feb-15 18:23 
GeneralRe: How to detect a mouse click outside a focused control Pin
Eddy Vluggen10-Feb-15 22:27
professionalEddy Vluggen10-Feb-15 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.