据我所知和我所读的,将DropDownStyle属性设置为DropDownList的ComboBox是以下各项的组合:
文本框,该文本框不显示光标,仅在用户按下向上,向下或等效于列表中项目的键时显示项目。例如,如果在DropDownList上有一个名为INPUT的项和一个名为OUTPUT的项,则按I键,组合框将显示INPUT,而按O键将显示OUTPUT;
一个按钮,其中显示了DropDownList;
DropDownList ,仅当用户按下Button时才会删除。
假设以上内容正确无误,请允许我提及我到目前为止所做的尝试。我已经搜索了处理上面提到的三个元素的方法,并找到了一些答案,不幸的是,大多数答案都与ASP.NET和C#.NET有关。
我已经成功设置了DropDownList上项目的默认状态和选定状态的BackColor和ForeColor。
我尝试在此TextBox的TextBox元素和DropDownList元素的边框上绘制一个Rectangle,但是这些矩形仍位于实际边框之下。
Private Sub cmbType_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cmbType.DrawItem
Dim itemBackColorDefault As Brush, itemForeColorDefault As Brush
Dim itemBackColorSelected As Brush, itemForeColorSelected As Brush
itemBackColorDefault = Brushes.DarkGray
itemForeColorDefault = Brushes.WhiteSmoke
itemBackColorSelected = Brushes.WhiteSmoke
itemForeColorSelected = Brushes.DarkGray
Dim myPen As Pen
Dim myGraphics As Graphics = Me.CreateGraphics
myPen = New Pen(Drawing.Color.Red, 1)
myGraphics.DrawRectangle(myPen, 133, 25, 130, 20) 'Supposed to draw a red rectangle above the border of the element TextBox of cmbType, but it stays beneath it
e.Graphics.DrawRectangle(myPen, -1, -1, 130, 31) 'Supposed to draw a red rectangle above the border of the element DropDownList of cmbType when the element Button of cmbType is clicked, but, again, it stays beneath it
If e.Index < 0 Then Exit Sub
Dim rct As Rectangle = e.Bounds
Dim itemText As String = cmbType.Items(e.Index)
If e.State And DrawItemState.Selected Then
'Selected BackColor
e.Graphics.FillRectangle(itemBackColorSelected, rct)
'Selected ForeColor
e.Graphics.DrawString(itemText, Me.cmbType.Font, itemForeColorSelected, rct.X, rct.Y)
Else
'Default BackColor
e.Graphics.FillRectangle(itemBackColorDefault, rct)
'Default ForeColor
e.Graphics.DrawString(itemText, Me.cmbType.Font, itemForeColorDefault, rct.X, rct.Y)
End If
End Sub
预期结果和实际结果可以汇总在一张图中:
LEFT is the actual result, RIGHT is the expected result.
更具体地说,我要更改的内容如下。
文本框:边框颜色;
按钮:边框颜色和BackColor,箭头颜色和形状;
DropDownList :边框颜色(默认状态和选中状态)。