ComboBox MeasureItem घटना फायरिंग नहीं

0

सवाल

मैं कोशिश कर रहा हूँ को विकसित करने के लिए एक कस्टम combobox (जो है में एक toolstrip) में जो कर रहे हैं आइटम 5 फ़ॉन्ट शैली है कि मैं होगा प्रदर्शन के रूप में वे देखो.

समस्या: मैं नहीं कर सकता के आकार सेट प्रत्येक आइटम. के MeasureItem घटना नहीं है, आग और मैं नहीं कर सकते हैं क्यों बाहर का पता लगाएं.

तो यह इस तरह दिखता है: enter image description here

दूर नहीं, लेकिन काफी नहीं मेरी गति! ^^

यहाँ अपने कोड:

Public CorpusFontStyleTitre1 As Font = New Font(New FontFamily("Lato"), 18, FontStyle.Bold, 3)
Public CorpusFontStyleTitre2 As Font = New Font(New FontFamily("Lato"), 16, FontStyle.Underline Or FontStyle.Bold, 3)
Public CorpusFontStyleTitre3 As Font = New Font(New FontFamily("Lato"), 14, FontStyle.Underline Or FontStyle.Bold, 3)
Public CorpusFontStyleTitre4 As Font = New Font(New FontFamily("Lato"), 12, FontStyle.Underline, 3)
Public CorpusFontStyleCorpsdeTexte As Font = New Font(New FontFamily("Lato"), 12, FontStyle.Regular, 3)

Public Structure CorpusFontStyleItem
        Dim strTextStyleName As String
        Dim fontTextStyle As Font
        Public Overrides Function ToString() As String
            Return strTextStyleName
        End Function
End Structure

Private Sub frmCorpusManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadcmbFontStyle()
        cmbFontStyle.ComboBox.DrawMode = DrawMode.OwnerDrawFixed
        AddHandler cmbFontStyle.ComboBox.DrawItem, AddressOf cmbFontStyle_DrawItem
        AddHandler cmbFontStyle.ComboBox.MeasureItem, AddressOf cmbFontStyle_MeasureItem
End Sub

Private Sub cmbFontStyle_MeasureItem(ByVal sender As Object, ByVal e As MeasureItemEventArgs)
        Select Case e.Index
            Case "1"
                e.ItemHeight = 50
            Case "2"
                e.ItemHeight = 40
            Case "3"
                e.ItemHeight = 30
            Case "4"
                e.ItemHeight = 20
            Case "5"
                e.ItemHeight = 10
        End Select

End Sub

Private Sub cmbFontStyle_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
        e.DrawBackground()
        Dim myItem As CorpusFontStyleItem = DirectCast(cmbFontStyle.Items(e.Index), CorpusFontStyleItem)
        e.Graphics.DrawString(myItem.strTextStyleName, myItem.fontTextStyle, New SolidBrush(Color.Black), e.Bounds)
        e.DrawFocusRectangle()
End Sub  

Private Sub LoadcmbFontStyle()

        Dim itemCorpusFontStyleTitre1 As New CorpusFontStyleItem With {.strTextStyleName = "Titre 1", .fontTextStyle = CorpusFontStyleTitre1}
        Dim itemCorpusFontStyleTitre2 As New CorpusFontStyleItem With {.strTextStyleName = "Titre 2", .fontTextStyle = CorpusFontStyleTitre2}
        Dim itemCorpusFontStyleTitre3 As New CorpusFontStyleItem With {.strTextStyleName = "Titre 3", .fontTextStyle = CorpusFontStyleTitre3}
        Dim itemCorpusFontStyleTitre4 As New CorpusFontStyleItem With {.strTextStyleName = "Titre 4", .fontTextStyle = CorpusFontStyleTitre4}
        Dim itemCorpusFontStyleCorps As New CorpusFontStyleItem With {.strTextStyleName = "Corps de Texte", .fontTextStyle = CorpusFontStyleCorpsdeTexte}

        cmbFontStyle.Items.Add(itemCorpusFontStyleTitre1)
        cmbFontStyle.Items.Add(itemCorpusFontStyleTitre2)
        cmbFontStyle.Items.Add(itemCorpusFontStyleTitre3)
        cmbFontStyle.Items.Add(itemCorpusFontStyleTitre4)
        cmbFontStyle.Items.Add(itemCorpusFontStyleCorps)

End Sub
combobox vb.net winforms
2021-11-19 14:18:54
1

सबसे अच्छा जवाब

3

आप उपयोग कर रहे हैं गलत मोड ड्रा. इसे बदलने के लिए, इस:

cmbFontStyle.ComboBox.DrawMode = DrawMode.OwnerDrawVariable

इसके अलावा, Select Case e.Index है एक पूर्णांक, एक स्ट्रिंग नहीं. यह शून्य आधारित है, तो आप नहीं कर रहे हैं को मापने के लिए पहला आइटम. इसे बदलने के लिए:

Select Case e.Index
  Case 0
    e.ItemHeight = 50
  Case 1
    e.ItemHeight = 40

आप की कोशिश करनी चाहिए वास्तव में मापने के लिए एक फ़ॉन्ट ऊंचाई अनुमान लगाने के बजाय एक नंबर पर.

2021-11-19 16:08:05

धन्यवाद और फिर से के लिए नि: शुल्क सलाह! ^^
8oris

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में