1

首先,我确实使用 ownerdrawvariable mod 制作了一个组合框,因为我想通过鼠标悬停来处理工具提示。为此,我处理了两个方法 DrawItem 和 MeasureItem :

    Private Sub DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cboPneuGlobal.DrawItem

    If e.Index = -1 Then
        Exit Sub
    End If

    e.DrawBackground()

    Dim p As Point = New Point(CInt(cboPneuGlobal.Location.X * Ratio), CInt(cboPneuGlobal.Location.Y * Ratio))
    Dim brColor As Brush = Brushes.Black

    If e.State = DrawItemState.Selected Then
        ToolTipFormBase.Show(CType(cboPneuGlobal.Items(e.Index), clsPneuEtTypeMarque).ToDisplay, Me, p)
        brColor = Brushes.White
    End If


    e.Graphics.DrawString(CType(cboPneuGlobal.Items(e.Index), clsPneuEtTypeMarque).ToDisplay, e.Font, brColor, New Point(e.Bounds.X, e.Bounds.Y))

End Sub

这里是第二个:

    Private Sub measureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles cboPneuGlobal.MeasureItem

    ' fetch the current item we’re painting as specified by the index
    Dim comboBoxItem As Object = cboPneuGlobal.Items(e.Index)

    ' measure the text of the item (in Whidbey consider using TextRenderer.MeasureText instead)
    Dim textSize As Size = e.Graphics.MeasureString(CType(cboPneuGlobal.Items(e.Index), clsPneuEtTypeMarque).ToDisplay, cboPneuGlobal.Font).ToSize()
    e.ItemHeight = textSize.Height
    e.ItemWidth = textSize.Width

End Sub

我遇到了一个小显示问题,组合框高度不符合我的项目的字体并且保持较小。这使我的文本被截断。看图片:

图片1

在此处输入图像描述

我做错了什么??

4

1 回答 1

0

与非 ownerdraw 组合框配合使用效果很好

于 2014-04-18T14:19:11.080 回答