如何在组合框中停止所选项目的颜色突出显示?

问题描述:





我在WinForm中使用组合框。

当我在组合框中选择任何项目时,然后选择项目背景颜色显示为蓝色。

我想删除这种蓝色背景颜色(特别是在表单加载时,尝试将焦点设置为表单中的其他控件,但组合高亮显示未删除)但还是希望选择项目。



有人可以帮帮忙吗?

Hi,

I am using combo box in WinForm.
When i'm selecting any item in combo box then selected item background color appears blue.
I want to remove this blue background color (particularly on form load, tried to set focus to other control in the form, but combo highlight not removed) yet want item to be selected.

Can someone help out on this please?

如果控件不允许你为所选项目设置背景颜色作为属性,然后您需要创建自己的所有者绘制控件以您想要的方式绘制。



有一个BackColor属性,设置时会发生什么?
If the control does not allow you to set a background color for selected items as a property, then you would need to create your own owner drawn control to draw in the way you want.

There is a BackColor property, what happens when you set that ?


组合框中的文本突出显示,因为焦点设置为组合框。选择组合框时,可以指示程序突出显示标签。这是有效的,因为标签在highligted时不会改变颜色。我的下面的代码有一个名为ddlSound的组合框和一个名为lblFiveName的标签。



Private Sub ddlSound_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles ddlSound.SelectedIndexChanged



如果ddlSound.Text =Sound On那么

bSound = True

结束If



如果ddlSound.Text =Sound Off那么

bSound = False

结束如果



lblFiveName.Focus()'此行从组合框中删除蓝色焦点



End Sub
Your text in the combo box is highlighted because the focus is set to your combo box. When you select your combo box, you can direct your program to highlight a label. This works because labels do not change colors when highligted. My below code has a combo box entitled ddlSound and a label entitled lblFiveName.

Private Sub ddlSound_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlSound.SelectedIndexChanged

If ddlSound.Text = "Sound On" Then
bSound = True
End If

If ddlSound.Text = "Sound Off" Then
bSound = False
End If

lblFiveName.Focus() 'This line removes blue focus from combo box

End Sub