Kinger247
asked on
Flat Combobox and font ...
Hi all,
I need to create a flat style combo in vb.net. Here is mode code so far below, it works ok but I can’t figure out how to set the font ??
Any ideas ??
Thanks in advance,
K.
I need to create a flat style combo in vb.net. Here is mode code so far below, it works ok but I can’t figure out how to set the font ??
Any ideas ??
Thanks in advance,
K.
Imports System.Drawing.Drawing2D
Public Class ComboBox2
Inherits ComboBox
Public Property BorderColour As Color
Get
Return _BorderColour
End Get
Set(value As Color)
_BorderColour = value
Me.Invalidate()
End Set
End Property
Private _BorderColour As Color = Color.FromArgb(64, 64, 64)
Private _ButtonColour As Color = Color.LightGray
Private _Arrowcolour As Color = Color.Black
Public Sub New()
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
End Sub
Private ButtonSize As Size = Nothing
Private ButtonRectangle As Rectangle = Nothing
Private ButtonPath As GraphicsPath = Nothing
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
With e.Graphics
.SmoothingMode = SmoothingMode.HighSpeed
.InterpolationMode = InterpolationMode.High
.DrawRectangle(New Pen(New SolidBrush(_BorderColour), 1), New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
.FillRectangle(New SolidBrush(_ButtonColour), ButtonRectangle)
.DrawLine(New Pen(New SolidBrush(_BorderColour), 1), ButtonRectangle.Left, 0, ButtonRectangle.Left, Me.Height)
.SmoothingMode = SmoothingMode.HighSpeed
.InterpolationMode = InterpolationMode.High
End With
Dim ArrowSize As New Size(9, 5)
Dim path As GraphicsPath = New GraphicsPath
Dim iLeft As Integer = ButtonRectangle.Left + ((ButtonSize.Width / 2) - (ArrowSize.Width / 2))
Dim iTop As Integer = ButtonRectangle.Top + ((ButtonSize.Height / 2) - (ArrowSize.Height / 2))
path.AddPolygon(New Point() {New Point(iLeft, 0 + iTop), New Point(ArrowSize.Width + iLeft, iTop), New Point((ArrowSize.Width / 2) + iLeft, ArrowSize.Height + iTop), New Point(iLeft, 0 + iTop)})
e.Graphics.FillPath(New SolidBrush(Color.Black), path)
End Sub
Protected Overrides Sub OnResize(e As System.EventArgs)
MyBase.OnResize(e)
ButtonSize = New Size(19, Me.Height - 2)
ButtonRectangle = New Rectangle(Me.Width - ButtonSize.Width - 1, 1, ButtonSize.Width, ButtonSize.Height)
Me.Invalidate()
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER