VB.NET ComboBox - 当按下某个键时需要强制重绘
我正在使用 DrawItem 和 MeasureItem 事件来绘制具有 OwnerDrawVariable 的 DrawMode 的组合框。
基本上,我试图让用户用鼠标突出显示一个选择,然后按空格键切换歌曲列表的保存状态。然后,我调用表单的 Me.Refresh() 事件,尝试重绘表单和 ComboBox。
我遇到的问题是,只有作为主窗体上的控件的组合框本身(而不是下拉区域)正在重绘,并且下拉列表的鼠标突出显示选择后面的文本是没有像我认为应该的那样从红色变为黑色。如果我将鼠标移动到另一个选择,那么颜色实际上会更新。
这是代码片段。
If (e.KeyCode = Keys.Space) Then
If cmbList.SelectedItem IsNot Nothing Then
With DirectCast(cmbList.SelectedItem, SongTitle)
.bSave = Not .bSave
End With
End If
End If
e.Handled = True
Me.Refresh()
感谢您提供的任何帮助。
I am using a DrawItem and MeasureItem events to paint a combobox with a DrawMode of OwnerDrawVariable.
Basically, I'm trying to have the user highlight a selection with the mouse, and then press the space bar to toggle the Save status of a song list. Then I call the Me.Refresh() event for the form in an attempt to redraw the form and the ComboBox.
The problem that I am running into is that only the Combobox itself (not the drop-down area) that is a control on the main form is redrawing, and the text that is behind the mouse-highlighted selection of the drop-down list is not changing from Red to Black as I believe it should. If I move the mouse to another selection, then the color does in fact update.
Here is a snippet of the code.
If (e.KeyCode = Keys.Space) Then
If cmbList.SelectedItem IsNot Nothing Then
With DirectCast(cmbList.SelectedItem, SongTitle)
.bSave = Not .bSave
End With
End If
End If
e.Handled = True
Me.Refresh()
Thanks for any help you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
.RefreshItem
/.RefreshItems
而不是.Refresh
。请参阅此问题:动态更改项目中的文本Winforms 组合框
You need to use
.RefreshItem
/.RefreshItems
instead of.Refresh
.See this question: Dynamically changing the text of items in a Winforms ComboBox