未正确绘制的行 - ComboBox.DrawItem事件

时间:2014-10-03 00:24:18

标签: vb.net combobox

我在VB.NET中使用ComboBox控件的DrawItem事件在每个项目上绘制几行和一个文本。下拉控件后,正确绘制每个项目的文本,但所有行都叠加在第一个项目中。当我慢慢向下滚动到最后,每个项目的文本都被正确绘制但没有绘制线条。当我慢慢向上滚动到开头时,正确绘制每个项目的文本并正确绘制线条。当我快速向上或向下滚动时,每个项目的文本都被正确绘制,但这些行以组的形式叠加。有什么想法吗?

链接到显示此内容的图片:

https://drive.google.com/file/d/0B7ou-lLESO_OTjJuT0ZhdHRzV1U/view?usp=sharing

Private Sub cbxShape_DrawItem(sender As Object, e As DrawItemEventArgs) Handles cbxShape.DrawItem


    e.DrawBackground()
    With figureTypeList.figureTypes(e.Index)
        Dim n_points As Integer = .vertices.Count
        For i = 0 To n_points - 2
            Dim x1 As Integer = .vertices(i).X * 3000 + e.Bounds.Width / 2
            Dim y1 As Integer = .vertices(i).Y * 3000 + e.Bounds.Height / 2
            Dim x2 As Integer = .vertices(i + 1).X * 3000 + e.Bounds.Width / 2
            Dim y2 As Integer = .vertices(i + 1).Y * 3000 + e.Bounds.Height / 2
            Dim startpoint As New System.Drawing.Point(x1, y1)
            Dim endpoint As New System.Drawing.Point(x2, y2)
            e.Graphics.DrawLine(New System.Drawing.Pen(Brushes.DarkBlue, 2), startpoint, endpoint)
        Next i
    End With

    Dim size As Single = 10
    Dim myFont As System.Drawing.Font = _
        New System.Drawing.Font(FontFamily.GenericSansSerif, size, FontStyle.Bold)

    Dim rectangle As Rectangle = New Rectangle(2, e.Bounds.Top + 2, _
        8 * e.Bounds.Height, e.Bounds.Height - 4)

    e.Graphics.DrawString(figureTypeList.figureTypes(e.Index).name, myFont, _
                          System.Drawing.Brushes.Black, _
                          New RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y, _
                          e.Bounds.Width, e.Bounds.Height))
    e.DrawFocusRectangle()
End Sub

0 个答案:

没有答案