问题描述
你好.我需要一些有关ComboBox控件的绘图项目的帮助.
在大多数情况下,ComboBox都可以正常绘制.我可以上下滚动,一切都很好.问题是当我拖动滚动条缩略图"或框以更快地通过列表时.项目无法正确显示.
将ComboBox设置为DropDownList和OwnerDrawVariable.
我理解下面的代码不是很有意义,因为我可以使用Windows实现来绘制项目.我正在使用的程序以粗体显示某些项目,因此下面的代码仅说明了我遇到的问题.
感谢您的帮助!
Hi there. I need some help with drawing items for a ComboBox Control.
For the most part the ComboBox draws just fine. I can scroll up and down and everything is good. The problem is when I drag the scrollbar "thumb" or box to get through the list faster. The items do not display correctly.
The ComboBox is set to DropDownList and OwnerDrawVariable.
I understand the code below is not very meaningful as I could use the windows implementation to draw the items. The program I''m working on displays certain items in bold, so the code below just illustrates the problem I have.
Thanks for your help!!
Public Class Form1<br /><br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br /><br /> Dim i As Integer<br /><br /> For i = 1 To 200<br /> ComboBox1.Items.Add(i)<br /> Next<br /><br /> End Sub<br /><br /> Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem<br /><br /> If e.Index = -1 Then<br /> Exit Sub<br /> End If<br /><br /> e.DrawBackground()<br /><br /> e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString(), e.Font, New SolidBrush(Color.Black), e.Bounds.X, e.Bounds.Y)<br /><br /> End Sub<br /><br />End Class
推荐答案
我对自己遇到的问题感到沮丧,并在带有Vista的Virtual PC上尝试了可执行文件,这没有问题.发现问题出在Windows 7上.我当前正在使用RC.
I was frustrated with the issue I was having, and tried the executable using Virtual PC with Vista and there was no problem. Discovered that the issue was with Windows 7. I am currently using the RC.
在使用OwnerDrawing组合框的其他程序中也发生了同样的问题.
The same issue occurs with in other programs that use OwnerDrawing for comboboxes.
再次感谢.
这篇关于组合框-DrawItem和拖动滚动条问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!