Monday, May 26, 2014

Apply ComboBox Border Color in VB.NET

Here's a simple way to decorate border color in Combobox control. The solution is a conversion of C# code originally developed by a C# Corner forum member.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        AddHandler Me.Paint, AddressOf DrawBorder
    End Sub
 
    Private Sub DrawBorder(ByVal sender As Object, ByVal e As PaintEventArgs)
        Dim rect As New Rectangle(Me.ComboBox1.Location.X - 1,
                                  Me.ComboBox1.Location.Y - 1,
                                  Me.ComboBox1.Width + 1,
                                  Me.ComboBox1.Height + 1)
 
        Dim pen As New Pen(Color.Red, 1)
        Dim g As Graphics = e.Graphics
        g.DrawRectangle(pen, rect)
    End Sub

Customized Combobox

0 comments:

Post a Comment