[求救]:怎么用comboBox来实现颜色的菜单阿
怎么才能用comboBox控件来实现带各种颜色属性的下拉菜单阿~
问题点数:20、回复次数:10Top
1 楼wangchong(网虫)回复于 2005-08-05 11:53:36 得分 0
可以用其他控件呀Top
2 楼henrysap(henry)回复于 2005-08-05 12:59:49 得分 0
不明白你要问什么.........Top
3 楼Windowspx(点NET)回复于 2005-08-05 13:09:26 得分 0
怎么说呢,在vb.net中,要实现就是在ComboBox的下拉菜单中要有20个选项,而这些选项都是各种的颜色条来提供选择,而不是单一的文本,这又和.net中自带的colordialog不太一样,不知道怎么弄了,是不是要用 图片的形式来实现阿?? 请教各位了Top
4 楼ConanKid()回复于 2005-08-05 14:52:04 得分 0
COMBOBOX好像没有这个功能,找找第三方控件吧Top
5 楼hamadou(闵峰--为了理想而奋斗)回复于 2005-08-06 14:35:24 得分 10
看下我的这个BLOG吧!
http://blog.csdn.net/hamadou/admin/EditPosts.aspxTop
6 楼sz_lgp(longguoping)回复于 2005-08-06 15:08:28 得分 0
upTop
7 楼hamadou(闵峰--为了理想而奋斗)回复于 2005-08-06 15:51:31 得分 0
SORRY!地址有误!呵呵,应该是这个
http://blog.csdn.net/hamadou/archive/2005/08/06/447127.aspxTop
8 楼caojinrong(小曹)回复于 2005-08-07 01:09:43 得分 0
重载On_Paint事件,画你想显示的东西.Top
9 楼caojinrong(小曹)回复于 2005-08-07 01:10:21 得分 0
不好意思,是Paint方法.Top
10 楼caojinrong(小曹)回复于 2005-08-13 15:21:12 得分 10
这么长时间还没结帖,算了,给你个现成的吧.
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
'图形化界面的ListControl,暂提供ListBox和ComboBox
'每个控件又分为颜色、图标和图像三种,相信差不多够用了
'***************************************************
'作者:小曹
'
'***************************************************
#Region "带颜色的ListBox"
#Region "带颜色的ListBoxItem"
Public Structure ColorListItem
Public Text As String
Public Color As Color
Public Sub New(ByVal gText As String, ByVal gColor As Color)
Text = gText
Color = gColor
End Sub
End Structure
#End Region
#Region "带颜色的ListBoxItems"
Public Class ColorListBoxItems
Inherits System.Collections.ArrayList
Public Event ColorListBoxItemsChanged()
Public Shadows Property Item(ByVal i) As ColorListItem
Get
Return MyBase.Item(i)
End Get
Set(ByVal Value As ColorListItem)
MyBase.Item(i) = Value
RaiseEvent ColorListBoxItemsChanged()
End Set
End Property
Public Shadows Sub Add(ByVal Item As ColorListItem)
MyBase.Add(Item)
RaiseEvent ColorListBoxItemsChanged()
End Sub
Public Shadows Sub Add(ByVal Text As String, ByVal Color As Color)
Add(New ColorListItem(Text, Color))
End Sub
Public Shadows Sub Remove(ByVal Index As Integer)
Remove(Me.Item(Index).Text, Me.Item(Index).Color)
End Sub
Public Shadows Sub Remove(ByVal Text As String, ByVal Color As Color)
MyBase.Remove(New ColorListItem(Text, Color))
RaiseEvent ColorListBoxItemsChanged()
End Sub
Public Shadows Sub Clear()
MyBase.Clear()
RaiseEvent ColorListBoxItemsChanged()
End Sub
End Class
#End Region
Public Class ColorListBox
Inherits System.Windows.Forms.ListBox
Dim WithEvents mColorItems As New ColorListBoxItems
Public Shadows Property Items() As ColorListBoxItems
Get
Return mColorItems
End Get
Set(ByVal Value As ColorListBoxItems)
mColorItems = Value
End Set
End Property
Public Sub New()
DrawMode = DrawMode.OwnerDrawFixed
ItemHeight = ItemHeight + 1
End Sub
Private Sub ItemsChanged() Handles mColorItems.ColorListBoxItemsChanged
MyBase.Items.Clear()
For i As Short = 0 To mColorItems.Count - 1
MyBase.Items.Add(mColorItems.Item(i).Text)
Next
End Sub
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim bounds As Rectangle = e.Bounds
Dim selected As Boolean = ((e.State And DrawItemState.Selected) > 0)
Dim editSel As Boolean = ((e.State And DrawItemState.ComboBoxEdit) > 0)
If e.Index <> -1 Then
DrawListBoxItem(g, bounds, e.Index, selected, editSel)
End If
End Sub
Protected Sub DrawListBoxItem(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal Index As Integer, ByVal selected As Boolean, ByVal editSel As Boolean)
If Index <> -1 Then
If selected And (Not editSel) Then
g.FillRectangle(New SolidBrush(SystemColors.Highlight), bounds.Left, bounds.Top, bounds.Width, bounds.Height)
Else
g.FillRectangle(New SolidBrush(SystemColors.Window), bounds.Left, bounds.Top, bounds.Width, bounds.Height)
End If
Dim ItemName As String = Items.Item(Index).Text
Dim ItemColor As Color = Items.Item(Index).Color
Dim brush As Brush
If selected Then
brush = New SolidBrush(SystemColors.HighlightText)
Else
brush = New SolidBrush(SystemColors.MenuText)
End If
g.FillRectangle(New SolidBrush(ItemColor), bounds.Left + 2, bounds.Top + 2, 20, bounds.Height - 4)
Dim blackPen As Pen = New Pen(New SolidBrush(Color.Black), 1)
g.DrawRectangle(blackPen, New Rectangle(bounds.Left + 1, bounds.Top + 1, 21, bounds.Height - 3))
g.DrawString(ItemName, SystemInformation.MenuFont, brush, New PointF(bounds.Left + 28, bounds.Top))
End If
End Sub
End Class
#End Region
Top
相关问题
- 怎样实现ComboBox离开时关闭DropDown菜单。
- 怎样实现ComboBox离开时关闭DropDown菜单。
- 请问金山词霸2001共享板中的菜单,鼠标选中时那种颜色逐渐渐淡的颜色条是如何实现的?
- 如何在程序中实现让combobox控件弹出下拉菜单(它好像没这个方法)
- 如何在delphi中实现联动菜单?-在COMBOBOX控件中(如选择省市县)
- 如何实现菜单……
- 有没有人注意过浩方对战平台的主界面窗口上菜单的颜色都跟普通菜单不一样啊,连其中WebBrowser控件的颜色都改了,是怎么实现的?
- VB能改变菜单颜色吗?
- 怎么在同一个COMBOBOX框里实现不同的项目(Items)有不同的颜色
- 100分送出,请教如何实现ComboBox->Enabled=false后,字体颜色设为除灰色之外的其他颜色比如黑色。




