うp
AQUA's .NET 奮闘記:はじめての自作UI ?
ざっとコードうp。
オーナードローは
DOBON.NET:ComboBoxの項目を自分で描画する
をまるっと拝借。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmb As ComboBox = Me.ToolStripComboBox1.ComboBox
cmb.DrawMode = DrawMode.OwnerDrawFixed
Dim ifc As New System.Drawing.Text.InstalledFontCollection
Dim ffs As FontFamily() = ifc.Families
Dim ff As FontFamilyFor Each ff In ffs
If ff.IsStyleAvailable(FontStyle.Regular) Then
cmb.Items.Add(ff.Name)End If
Next ff
AddHandler cmb.DrawItem, AddressOf Me.cmb_DrawItem
End Sub
Private Sub cmb_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
e.DrawBackground()
Dim cmb As ComboBox = CType(sender, ComboBox)
Dim txt As String
If e.Index > -1 Then
txt = cmb.Items(e.Index).ToString()
Else
txt = cmb.Text
End IfDim f As New Font(txt, cmb.Font.Size)
Dim b As New SolidBrush(e.ForeColor)
Dim ym As Single = (e.Bounds.Height - e.Graphics.MeasureString(txt, f).Height) / 2e.Graphics.DrawString(txt, f, b, e.Bounds.X, e.Bounds.Y + ym)
f.Dispose()
b.Dispose()e.DrawFocusRectangle()
End Sub
End Class