Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

Here's one that I partically borrowed and modified...it might be what you're looking for.

 

Make a user control named FlatCombo and paste in the following code.

 

Public Class FlatCombo
   Inherits ComboBox

   Private BorderBrush As Brush = New SolidBrush(SystemColors.Window)
   Private EditBoxBrush As Brush = New SolidBrush(Me.BackColor)
   Private ArrowBrush As Brush = New SolidBrush(SystemColors.ControlText)
   Private DropButtonBrush As Brush = New SolidBrush(SystemColors.Control)
   Private ButtonColor As Color = SystemColors.Control
   Private EnabledColor As Color = MyBase.ForeColor
   Private DisabledColor As Color = Color.Gray

#Region " Protected Overrides Events"

   Protected Overrides Sub WndProc(ByRef m As Message)
       MyBase.WndProc(m)

       DropButtonBrush = New SolidBrush(Me.ButtonColor)
       Select Case m.Msg
           Case &HF
               Dim g As Graphics = Me.CreateGraphics
               'Dim p As Pen = New Pen(Color.White, 1)

               g.FillRectangle(BorderBrush, Me.ClientRectangle)

               'Draw the background of the dropdown button
               Dim rectDropButton As Rectangle = New Rectangle(Me.Width - 13, 1, 12, Me.Height - 2)
               g.FillRectangle(DropButtonBrush, rectDropButton)

               'Draw the Edit Box
               Dim rectEditBox As Rectangle = New Rectangle(1, 1, Me.Width - 15, Me.Height - 2)
               g.FillRectangle(EditBoxBrush, rectEditBox)

               'Create the path for the arrow
               Dim pth As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath()
               Dim TopLeft As PointF = New PointF(Me.Width - 10, (Me.Height - 5) / 2)
               Dim TopRight As PointF = New PointF(Me.Width - 4, (Me.Height - 5) / 2)
               Dim Bottom As PointF = New PointF(Me.Width - 7, (Me.Height + 1) / 2)
               pth.AddLine(TopLeft, TopRight)
               pth.AddLine(TopRight, Bottom)

               g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

               'Determine the arrow's color.
               If Me.DroppedDown Then
                   ArrowBrush = New SolidBrush(Color.White)
               Else
                   ArrowBrush = New SolidBrush(SystemColors.ControlText)
               End If

               'Draw the arrow
               g.FillPath(ArrowBrush, pth)
               g.Dispose()

           Case Else
               Exit Select
       End Select

       'MsgBox(m.Msg)
   End Sub

   Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
       MyBase.OnLostFocus(e)
       BorderBrush = New SolidBrush(SystemColors.Window)
       ButtonColor = SystemColors.Control
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
       MyBase.OnGotFocus(e)
       BorderBrush = New SolidBrush(SystemColors.Highlight)
       ButtonColor = Color.FromArgb(182, 189, 210)
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
       If Me.Enabled = True Then
           Me.ForeColor = EnabledColor
           Me.IntegralHeight = True
           EditBoxBrush = New SolidBrush(MyBase.BackColor)
       Else
           Me.ForeColor = DisabledColor
           Me.IntegralHeight = False
           EditBoxBrush = New SolidBrush(ButtonColor)
       End If
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnBackColorChanged(ByVal e As System.EventArgs)
       MyBase.OnBackColorChanged(e)
       EditBoxBrush = New SolidBrush(MyBase.BackColor)
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnSelectionChangeCommitted(ByVal e As System.EventArgs)
       MyBase.OnSelectionChangeCommitted(e)
       BorderBrush = New SolidBrush(SystemColors.Window)
       ButtonColor = SystemColors.Control
       Me.Invalidate()
   End Sub

   'Auto complete
   Private m_LastValue As String = ""
   Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
       Dim FindString As String
       Select Case Asc(e.KeyChar)
           Case Keys.Escape, Keys.Back
               Text = ""
           Case Else
               Dim txtLen As Integer = Text.Length
               Dim     As Integer = Me.FindString(Text)
               If     <> -1 Then
                   Text = Items(   )
                   SelectionStart = txtLen
                   SelectionLength = Text.Length
                   m_LastValue = Text
               Else
                   Text = m_LastValue
                   SelectionStart = 0
                   SelectionLength = m_LastValue.Length
               End If
       End Select
       e.Handled = True
   End Sub
#End Region

#Region "Mouse Overrides Events"

   Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
       MyBase.OnMouseEnter(e)
       BorderBrush = New SolidBrush(SystemColors.Highlight)
       ButtonColor = Color.FromArgb(182, 189, 210)
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
       MyBase.OnMouseLeave(e)
       If Me.Focused Then Exit Sub
       BorderBrush = New SolidBrush(SystemColors.Window)
       ButtonColor = SystemColors.Control
       Me.Invalidate()
   End Sub

   Protected Overrides Sub OnMouseHover(ByVal e As System.EventArgs)
       MyBase.OnMouseHover(e)
       BorderBrush = New SolidBrush(SystemColors.Highlight)
       ButtonColor = Color.FromArgb(182, 189, 210)
       Me.Invalidate()
   End Sub
#End Region

End Class

 

Hope that'll help

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

WoW, thanks a lot...looks nice..

but have a look at the OnKeyPress Sub, its missing stuff..

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

  • *Experts*
Posted (edited)

You're right??? I guess cut and paste have their limitations.

 

Fill the blanks in with the word "word"...

 

Dim word As Integer = Me.FindString(Text)

If word <> -1 Then

Text = Items(word)

 

That should do it.

Dan

 

Wow..." " disappears even here!!! so remove the quotes leaving only the word.

 

p...o...s is the word

Edited by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Awsome

 

Thats what i call a combo... couldnt hope better...thanks DiverDan

 

(Just to be a pain: the RightToLeft property doesnt behave properly though! );)

Auto-suggestion: "I have a life"

Uncontroled thinking: "So what the.."

  • 3 years later...
Posted

HI.

 

In the control designer giver the error :

Error: 'AutoScaleMode' is not a member of 'WindowsApplication1.FlatCombo'.

 

How can i resolve this?

 

 

CODE:

 

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class FlatCombo

Inherits System.Windows.Forms.ComboBox

 

'UserControl overrides dispose to clean up the component list.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

MyBase.Dispose(disposing)

End Sub

 

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

 

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

components = New System.ComponentModel.Container()

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

End Sub

 

End Class

 

 

thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...