【问题标题】:Setting Combobox Height OwnerDrawVariable ( Unexpected display result )设置组合框高度 OwnerDrawVariable(意外显示结果)
【发布时间】:2013-07-03 17:07:37
【问题描述】:

首先,我确实使用 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

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

我做错了什么??

【问题讨论】:

  • 我们只是不为应用程序使用视觉主题。与非 ownerdraw 组合框配合使用效果很好

标签: vb.net winforms combobox drawing controls


【解决方案1】:

与非所有者绘制组合框配合使用效果很好

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 2011-02-02
    • 2012-06-22
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多