一个自定义的Combox
来源:互联网 发布:网站怎么优化排名靠前 编辑:程序博客网 时间:2024/05/01 05:20
如何在windows标准的combox中加入自定义的item
Public Class ComboPatternClass ComboPattern
Inherits System.Windows.Forms.ComboBox
Component Designer generated code#Region " Component Designer generated code "
Public Sub New()Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
'get or set current pattern style
Private _patternstyle As System.Drawing.Drawing2D.HatchStyle
Public Property PatternStyle()Property PatternStyle() As System.Drawing.Drawing2D.HatchStyle
Get
Return _patternstyle
End Get
Set(ByVal Value As System.Drawing.Drawing2D.HatchStyle)
_patternstyle = Value
End Set
End Property
Protected Overrides Sub OnDrawItem()Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
MyBase.OnDrawItem(e)
Me.DrawMode = DrawMode.OwnerDrawFixed
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Color.Gray)
selectPen.DashStyle = Drawing2D.DashStyle.Dash
e.Graphics.DrawRectangle(selectPen, e.Bounds)
Else
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Me.BackColor)
e.Graphics.DrawRectangle(selectPen, e.Bounds)
End If
' e.DrawBackground()
e.DrawFocusRectangle()
Dim myBrush As System.Drawing.Drawing2D.HatchBrush
Select Case e.Index
Case 0
'no pattern
Case 1
'BackwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, Color.Black, Me.BackColor)
Case 2
'Cross
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Black, Me.BackColor)
Case 3
'DarkDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkDownwardDiagonal, Color.Black, Me.BackColor)
Case 4
'DarkHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkHorizontal, Color.Black, Me.BackColor)
Case 5
'DarkUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkUpwardDiagonal, Color.Black, Me.BackColor)
Case 6
'DarkVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkVertical, Color.Black, Me.BackColor)
Case 7
'DashedDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedDownwardDiagonal, Color.Black, Me.BackColor)
Case 8
'DashedHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedHorizontal, Color.Black, Me.BackColor)
Case 9
'DashedUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedUpwardDiagonal, Color.Black, Me.BackColor)
Case 10
'DashedVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedVertical, Color.Black, Me.BackColor)
End Select
'e.Graphics.DrawRectangle(myPen, New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
If e.Index = 0 Then
Dim myBrush1 As New SolidBrush(Color.Black)
e.Graphics.DrawString(Me.Items(e.Index), e.Font, myBrush1, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
Else
'e.Graphics.DrawLine(myPen, e.Bounds.X, e.Bounds.Y + CInt(e.Bounds.Height / 2), e.Bounds.X + e.Bounds.Width, e.Bounds.Y + CInt(e.Bounds.Height / 2))
e.Graphics.FillRectangle(myBrush, e.Bounds)
End If
End Sub
Private Sub ComboPattern_SelectedIndexChanged()Sub ComboPattern_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SelectedIndexChanged
If (Me.DropDownStyle <> ComboBoxStyle.DropDownList) Then
Me.DropDownStyle = ComboBoxStyle.DropDownList
End If
Dim currentPattern As System.Drawing.Drawing2D.HatchStyle
Select Case Me.SelectedIndex
Case 0
'no pattern, use ZigZag to instead of
currentPattern = Drawing2D.HatchStyle.ZigZag
Case 1
'BackwardDiagonal
currentPattern = Drawing2D.HatchStyle.BackwardDiagonal
Case 2
'Cross
currentPattern = Drawing2D.HatchStyle.Cross
Case 3
'DarkDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkDownwardDiagonal
Case 4
'DarkHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal
Case 5
'DarkUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkUpwardDiagonal
Case 6
'DarkVertical
currentPattern = Drawing2D.HatchStyle.DarkVertical
Case 7
'DashedDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedDownwardDiagonal
Case 8
'DashedHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal
Case 9
'DashedUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedUpwardDiagonal
Case 10
'DashedVertical
currentPattern = Drawing2D.HatchStyle.DashedVertical
End Select
Me.PatternStyle = currentPattern
End Sub
End Class
Inherits System.Windows.Forms.ComboBox
Component Designer generated code#Region " Component Designer generated code "
Public Sub New()Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New()Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
#End Region
'get or set current pattern style
Private _patternstyle As System.Drawing.Drawing2D.HatchStyle
Public Property PatternStyle()Property PatternStyle() As System.Drawing.Drawing2D.HatchStyle
Get
Return _patternstyle
End Get
Set(ByVal Value As System.Drawing.Drawing2D.HatchStyle)
_patternstyle = Value
End Set
End Property
Protected Overrides Sub OnDrawItem()Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
MyBase.OnDrawItem(e)
Me.DrawMode = DrawMode.OwnerDrawFixed
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Color.Gray)
selectPen.DashStyle = Drawing2D.DashStyle.Dash
e.Graphics.DrawRectangle(selectPen, e.Bounds)
Else
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Me.BackColor)
e.Graphics.DrawRectangle(selectPen, e.Bounds)
End If
' e.DrawBackground()
e.DrawFocusRectangle()
Dim myBrush As System.Drawing.Drawing2D.HatchBrush
Select Case e.Index
Case 0
'no pattern
Case 1
'BackwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, Color.Black, Me.BackColor)
Case 2
'Cross
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Black, Me.BackColor)
Case 3
'DarkDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkDownwardDiagonal, Color.Black, Me.BackColor)
Case 4
'DarkHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkHorizontal, Color.Black, Me.BackColor)
Case 5
'DarkUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkUpwardDiagonal, Color.Black, Me.BackColor)
Case 6
'DarkVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkVertical, Color.Black, Me.BackColor)
Case 7
'DashedDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedDownwardDiagonal, Color.Black, Me.BackColor)
Case 8
'DashedHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedHorizontal, Color.Black, Me.BackColor)
Case 9
'DashedUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedUpwardDiagonal, Color.Black, Me.BackColor)
Case 10
'DashedVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedVertical, Color.Black, Me.BackColor)
End Select
'e.Graphics.DrawRectangle(myPen, New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
If e.Index = 0 Then
Dim myBrush1 As New SolidBrush(Color.Black)
e.Graphics.DrawString(Me.Items(e.Index), e.Font, myBrush1, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
Else
'e.Graphics.DrawLine(myPen, e.Bounds.X, e.Bounds.Y + CInt(e.Bounds.Height / 2), e.Bounds.X + e.Bounds.Width, e.Bounds.Y + CInt(e.Bounds.Height / 2))
e.Graphics.FillRectangle(myBrush, e.Bounds)
End If
End Sub
Private Sub ComboPattern_SelectedIndexChanged()Sub ComboPattern_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SelectedIndexChanged
If (Me.DropDownStyle <> ComboBoxStyle.DropDownList) Then
Me.DropDownStyle = ComboBoxStyle.DropDownList
End If
Dim currentPattern As System.Drawing.Drawing2D.HatchStyle
Select Case Me.SelectedIndex
Case 0
'no pattern, use ZigZag to instead of
currentPattern = Drawing2D.HatchStyle.ZigZag
Case 1
'BackwardDiagonal
currentPattern = Drawing2D.HatchStyle.BackwardDiagonal
Case 2
'Cross
currentPattern = Drawing2D.HatchStyle.Cross
Case 3
'DarkDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkDownwardDiagonal
Case 4
'DarkHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal
Case 5
'DarkUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkUpwardDiagonal
Case 6
'DarkVertical
currentPattern = Drawing2D.HatchStyle.DarkVertical
Case 7
'DashedDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedDownwardDiagonal
Case 8
'DashedHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal
Case 9
'DashedUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedUpwardDiagonal
Case 10
'DashedVertical
currentPattern = Drawing2D.HatchStyle.DashedVertical
End Select
Me.PatternStyle = currentPattern
End Sub
End Class
snapshot:
- 一个自定义的Combox
- 一个自定义的Combox
- 使用Combox控件的一个问题
- 自定义 既可输入文字又可选择的 控件ComBox
- 如何实现一个下拉框为JTree的Combox
- 如何实现一个下拉框为JTree的Combox
- DWZ select combox 级联中遇到的一个bug
- Combox的数据源
- combox的总结
- progstudio Combox 的问题
- Ext的Combox
- 似曾相识的Combox
- Ext的Combox
- combox的显示
- 可多选的combox
- COMBOX的基本使用
- combox
- 自定义 既可输入文字又可选择的 控件ComBox—2
- C#操作注册表及设置开机自动运行
- Oracle 面试题目
- GNU gprof
- 冒泡排序与选择排序
- hg版本管理工具使用
- 一个自定义的Combox
- 一个自定义的Combox
- c#.net常用函数和方法集
- iis5.1 独立包 安装方法
- 站点地图(4)
- Rose, Hell, Performance, Drawn
- 软件测试过程的监控方法
- 提高电脑速度
- 用VS2005制作网页对IIS进行操作(转帖)