Vb.net 设置组合框高度OwnerDrawVariable(意外显示结果)
首先,我用ownerdrawvariable mod制作了一个组合框,因为我想用鼠标悬停来处理工具提示。为此,我处理了两种方法DrawItem和MeasureItem:Vb.net 设置组合框高度OwnerDrawVariable(意外显示结果),vb.net,winforms,combobox,drawing,controls,Vb.net,Winforms,Combobox,Drawing,Controls,首先,我用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
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
我有一个小的显示问题,组合框的高度不符合我的项目的字体,并保持小。这使得我的文本被截断。如图所示:
我做错了什么?使用非所有者的Draw组合框非常好我们只是在应用程序中不使用视觉主题。这是一个伟大的工作与非所有者的组合框