add properties to control

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

I want to add text properties to control combobox
Be out of the control elements selection

Meaning if no element is selected from combobox

The txt is properties add displayed

I want to add texet freely as it is circulated to every project



I got this class

Class iTalk_ComboBox
Inherits ComboBox

#Region " Variables "

Private _StartIndex As Integer = 0
Private _HoverSelectionColor As Color = Color.FromArgb(241, 241, 241)
#End Region
#Region " Custom Properties "

Public Property StartIndex As Integer
Get
Return _StartIndex
End Get
Set(ByVal value As Integer)
_StartIndex = value
Try
MyBase.SelectedIndex = value
Catch
End Try
Invalidate()
End Set
End Property

Public Property HoverSelectionColor As Color
Get
Return _HoverSelectionColor
End Get
Set(ByVal value As Color)
_HoverSelectionColor = value
Invalidate()
End Set
End Property

#End Region
#Region " EventArgs "

Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e.Graphics.FillRectangle(New SolidBrush(_HoverSelectionColor), e.Bounds)
Else
e.Graphics.FillRectangle(Brushes.White, e.Bounds)
End If

If Not e.Index = -1 Then
e.Graphics.DrawString(GetItemText(Items(e.Index)), e.Font, Brushes.DimGray, e.Bounds)
End If
End Sub

Protected Overrides Sub OnLostFocus(ByVal e As EventArgs)
MyBase.OnLostFocus(e)
SuspendLayout()
Update()
ResumeLayout()
End Sub

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
MyBase.OnPaintBackground(e)
End Sub

#End Region

Sub New()
SetStyle(DirectCast(139286, ControlStyles), True)
SetStyle(ControlStyles.Selectable, False)
DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
DropDownStyle = ComboBoxStyle.DropDownList
BackColor = Color.FromArgb(246, 246, 246)
ForeColor = Color.FromArgb(142, 142, 142)
Size = New Size(135, 26)
ItemHeight = 20
DropDownHeight = 100
Font = New Font("Segoe UI", 10, FontStyle.Regular)
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim LGB As LinearGradientBrush
Dim GP As GraphicsPath

e.Graphics.Clear(BackColor)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

' Create a curvy border
GP = RoundRectangle.RoundRect(0, 0, Width - 1, Height - 1, 5)
' Fills the body of the rectangle with a gradient
LGB = New LinearGradientBrush(ClientRectangle, Color.FromArgb(241, 241, 241), Color.FromArgb(241, 241, 241), 90.0F)

e.Graphics.SetClip(GP)
e.Graphics.FillRectangle(LGB, ClientRectangle)
e.Graphics.ResetClip()

' Draw rectangle border
e.Graphics.DrawPath(New Pen(Color.FromArgb(204, 204, 204)), GP)
' Draw string
e.Graphics.DrawString(Text, Font, New SolidBrush(Color.FromArgb(142, 142, 142)), New Rectangle(3, 0, Width - 20, Height), New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Near})

' Draw the dropdown arrow
e.Graphics.DrawLine(New Pen(Color.FromArgb(160, 160, 160), 2), New Point(Width - 18, 10), New Point(Width - 14, 14))
e.Graphics.DrawLine(New Pen(Color.FromArgb(160, 160, 160), 2), New Point(Width - 14, 14), New Point(Width - 10, 10))
e.Graphics.DrawLine(New Pen(Color.FromArgb(160, 160, 160)), New Point(Width - 14, 15), New Point(Width - 14, 14))

GP.Dispose()
LGB.Dispose()
End Sub
End Class

Continue reading...
 
Back
Top