2022/09/12(Mon) 07:27:48 編集(投稿者)
■No100552 (wani さん) に返信
わたしの疑問には答えてもらえないんでしょうか?
> レベルが高すぎて私にはどのように作成したら良いか分かりません。
> どうやれば良いかコードをご提示いただけないでしょうか?
CP_BACKGROUND な VisualStyleElement は、作成はできるものの、SetPrameters でセットするとエラーになります。
API を使って直書きしてみたのですが、どうやら、DropDown スタイルのテーマのようです。
DropDownList スタイルの場合、背景はボタンを描画するのが正解のようです。
とりあえず、マウスがホバーしホットな状態の ComboBox を作ってみました。
あとは面倒なのでおまかせします。
状態を検出して VisualStyles.PushButtonState.Hot/CBXSR_HOT の部分を切り替えてください。
テキストの描画位置も要調整。
フォーカスを得たときの点線は、ControlPaint.DrawFocusRectangle メソッドを使って描画できます。
https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.controlpaint.drawfocusrectangle?view=netframework-4.5
Public Class ComboBoxEx
    Inherits ComboBox
    <ThreadStatic>
    Private Shared vsRenderer As VisualStyles.VisualStyleRenderer
    Private Shared dropdownButtonElement As VisualStyles.VisualStyleElement =
                VisualStyles.VisualStyleElement.CreateElement("COMBOBOX", CP_DROPDOWNBUTTONRIGHT, CBXSR_NORMAL)
    Private Const CP_BACKGROUND As Integer = 2
    Private Const CP_TRANSPARENTBACKGROUND As Integer = 3
    Private Const CP_BORDER As Integer = 4
    Private Const CP_READONLY As Integer = 5
    Private Const CP_DROPDOWNBUTTONRIGHT As Integer = 6
    Private Const CP_DROPDOWNBUTTONLEFT As Integer = 7
    Private Const CP_CUEBANNER As Integer = 8
    Private Const CBXSR_NORMAL As Integer = 1
    Private Const CBXSR_HOT As Integer = 2
    Private Const CBXSR_PRESSED As Integer = 3
    Private Const CBXSR_DISABLED As Integer = 4
    Protected Overrides Sub CreateHandle()
        MyBase.CreateHandle()
        Dim bUserPaint As Boolean = Application.RenderWithVisualStyles AndAlso
            DropDownStyle = ComboBoxStyle.DropDownList AndAlso
            FlatStyle = FlatStyle.Standard
        SetStyle(ControlStyles.UserPaint Or
                 ControlStyles.AllPaintingInWmPaint Or
                 ControlStyles.OptimizedDoubleBuffer, bUserPaint)
    End Sub
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        If vsRenderer Is Nothing Then
            vsRenderer = New VisualStyles.VisualStyleRenderer(dropdownButtonElement)
        End If
        If vsRenderer.IsBackgroundPartiallyTransparent() Then
            vsRenderer.DrawParentBackground(e.Graphics, ClientRectangle, Me)
        End If
        Dim cr As Rectangle = ClientRectangle
        Dim face As New Rectangle(-1, -1, cr.Width + 2, cr.Height + 2)
        Dim buttonWidth As Integer = SystemInformation.HorizontalScrollBarArrowWidth
        Dim buttonRect As New Rectangle(cr.Right - buttonWidth - 1, cr.Top, buttonWidth, cr.Height)
        Dim buttonFace As New Rectangle(buttonRect.X + 1, 0, buttonRect.Width - 2, buttonRect.Height - 2)
        ButtonRenderer.DrawButton(e.Graphics, face, VisualStyles.PushButtonState.Hot)
        vsRenderer.SetParameters(dropdownButtonElement.ClassName,
                                 dropdownButtonElement.Part,
                                 CBXSR_HOT)
        vsRenderer.DrawBackground(e.Graphics, buttonRect, buttonFace)
        TextRenderer.DrawText(e.Graphics, Text, Font, cr, ForeColor,
                              TextFormatFlags.Left Or TextFormatFlags.VerticalCenter)
    End Sub
End Class
使い方
Public Class Form1
    Public Sub New()
        InitializeComponent()
        Dim cbo As New ComboBoxEx
        cbo.Size = New Size(100, 20)
        cbo.Items.AddRange(New Object() {"AAA", "BBB", "CCC"})
        cbo.ForeColor = Color.Red
        cbo.DropDownStyle = ComboBoxStyle.DropDownList
        Controls.Add(cbo)
    End Sub
End Class
とまぁ、ここまで書いたんですが、たいていは面倒なのでやめます。とか無応答になっちゃうんですよね(^_^;)