none
combobox properties RRS feed

Answers

  • Hello,

    Here is one, I have the background color as yellow, change it to whatever color you want.

    Imports System.ComponentModel
    Imports System.Runtime.InteropServices
    
    Public Class ComboBoxCustom
        Inherits ComboBox
    
        <Category("Appearance"),
            Description("Set disabled background color")>
        Public Property DisabledBackGroundColor() As Color
    
        <DllImport("gdi32.dll")>
        Friend Shared Function CreateSolidBrush(ByVal color As Integer) As IntPtr
        End Function
    
        <DllImport("gdi32.dll")>
        Friend Shared Function SetBkColor(ByVal hdc As IntPtr, ByVal color As Integer) As Integer
        End Function
    
        Protected Overrides Sub WndProc(ByRef m As Message)
            MyBase.WndProc(m)
            Dim brush As IntPtr
            Select Case m.Msg
    
                Case 312
                    SetBkColor(m.WParam, ColorTranslator.ToWin32(DisabledBackGroundColor))
                    brush = CreateSolidBrush(ColorTranslator.ToWin32(DisabledBackGroundColor))
                    m.Result = brush
                Case Else
            End Select
        End Sub
    End Class



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Thursday, June 27, 2019 10:24 PM
    Moderator

All replies

  • Hello,

    Here is one, I have the background color as yellow, change it to whatever color you want.

    Imports System.ComponentModel
    Imports System.Runtime.InteropServices
    
    Public Class ComboBoxCustom
        Inherits ComboBox
    
        <Category("Appearance"),
            Description("Set disabled background color")>
        Public Property DisabledBackGroundColor() As Color
    
        <DllImport("gdi32.dll")>
        Friend Shared Function CreateSolidBrush(ByVal color As Integer) As IntPtr
        End Function
    
        <DllImport("gdi32.dll")>
        Friend Shared Function SetBkColor(ByVal hdc As IntPtr, ByVal color As Integer) As Integer
        End Function
    
        Protected Overrides Sub WndProc(ByRef m As Message)
            MyBase.WndProc(m)
            Dim brush As IntPtr
            Select Case m.Msg
    
                Case 312
                    SetBkColor(m.WParam, ColorTranslator.ToWin32(DisabledBackGroundColor))
                    brush = CreateSolidBrush(ColorTranslator.ToWin32(DisabledBackGroundColor))
                    m.Result = brush
                Case Else
            End Select
        End Sub
    End Class



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Thursday, June 27, 2019 10:24 PM
    Moderator
  • I was hoping that property already existed and I had just missed it.  Sigh.

    Anyway, thanks!

    I am motivated by my irritation over the combobox control and am now willing to learn, yet again, how to add a property to a control. I do appreciate the code, because that is one part of that process that I will never understand. 



    gwboolean

    Thursday, June 27, 2019 10:44 PM