掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ComboBoxのドロップダウンリストのバックカラーの色を変えない方法 (ID:144792)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
背景の色をWindowsのデフォルトを使うなら こんな感じでしょうか。 Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load ComboBox1.DropDownStyle = ComboBoxStyle.DropDown ComboBox1.DrawMode = DrawMode.OwnerDrawFixed For i As Integer = 1 To 10 ComboBox1.Items.Add(Format(i, "000") & "番目") Next i End Sub Private Sub ComboBox1_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.Enter ComboBox1.BackColor = Drawing.Color.LightSteelBlue End Sub Private Sub ComboBox1_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.Leave ComboBox1.ResetBackColor() End Sub Private Sub ComboBox1_DrawItem(ByVal o As Object, ByVal e As DrawItemEventArgs) Handles ComboBox1.DrawItem Dim grfx As Graphics = e.Graphics Dim rect As Rectangle = e.Bounds Dim flag As Boolean = (e.State And DrawItemState.Selected) <> 0 If e.Index = -1 Then Exit Sub If flag Then grfx.FillRectangle(New SolidBrush(ComboBox1.BackColor), rect) Else grfx.FillRectangle(SystemBrushes.Window, rect) End If grfx.DrawString(ComboBox1.Items(e.Index).ToString, e.Font, _ New SolidBrush(e.ForeColor), rect) e.DrawFocusRectangle() End Sub End Class
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.