支持Office Xp/2003样式的扁平ComboBox控件


0 导论

首先,在网上可以找到很多这样实现扁平效果的ComboBox代码.我试着实现了一个比较简单的ComboBox控件,但是它却有很多的功能.

正如截图所示,你会发现在此控件中,我集成有如下的功能:支持大号字体,从右至左显示文字,两种下拉样式,当然还包括支持Office Xp/2003两种样式.

1 两种不同样式下的状态

    捕捉_2.jpg
   从上到下依次是
:正常状态,输入焦点时,不起作用,下拉状态.

2 如何使用代码


FlatComboBox
是一个继承于.NetFrameworkWindows.Forms.ComboBox的用户控件
通过重写类库中的WinProc来激活MouseMove等事件

 1 ExpandedBlockStart.gif ContractedBlock.gif Protected   Overrides   Sub WndProc() Sub WndProc(ByRef m As _
 2InBlock.gif                       System.Windows.Forms.Message)
 3InBlock.gif        MyBase.WndProc(m)
 4InBlock.gif        Select Case m.Msg
 5InBlock.gif
 6InBlock.gif            Case &HF
 7InBlock.gif                'WM_PAINT
 8InBlock.gif
 9InBlock.gif                '"simple" is not currently supported
10InBlock.gif                If Me.DropDownStyle = _
11InBlock.gif                           ComboBoxStyle.Simple Then Exit Sub
12InBlock.gif
13InBlock.gif                '==========START DRAWING===========
14InBlock.gif                g = Me.CreateGraphics
15InBlock.gif                'clear everything
16InBlock.gif                If Me.Enabled Then
17InBlock.gif                    g.Clear(Color.White)
18InBlock.gif                Else
19InBlock.gif                    g.Clear(Color.FromName("control"))
20InBlock.gif                End If
21InBlock.gif                'call the drawing functions
22InBlock.gif                DrawButton(g)
23InBlock.gif                DrawArrow(g)
24InBlock.gif                DrawBorder(g)
25InBlock.gif                DrawText(g)
26InBlock.gif                '===========STOP DRAWING============
27InBlock.gif
28InBlock.gif            Case 78&H7, &H8, &H200, &H2A3
29InBlock.gif                'CMB_DROPDOWN, CMB_CLOSEUP, WM_SETFOCUS, 
30InBlock.gif                'WM_KILLFOCUS, WM_MOUSEMOVE,  
31InBlock.gif                'WM_MOUSELEAVE (if you move the mouse fast over
32InBlock.gif                'the combobox, mouseleave doesn't always react)
33InBlock.gif
34InBlock.gif                UpdateState()
35InBlock.gif        End Select
36ExpandedBlockEnd.gifEnd Sub

37 None.gif


通过Public属性来切换两种样式(Xp/2003):

 1 None.gif ' Property to let the user change the style
 2 ExpandedBlockStart.gifContractedBlock.gif      Public   Property FlatComboStyle() Property FlatComboStyle() As styles
 3InBlock.gif        Get
 4InBlock.gif            Return style
 5InBlock.gif        End Get
 6InBlock.gif        Set(ByVal Value As styles)
 7InBlock.gif            style = Value
 8InBlock.gif        End Set
 9ExpandedBlockEnd.gif    End Property

10 None.gif ps:本控件由vb.net实现.  可以通过在线转化工具很容易的转化成C#代码
原文出处:http://www.codeproject.com/vb/net/FlatComboBox.asp
源代码下载    Demo下载 

转载于:https://www.cnblogs.com/finesite/archive/2005/11/13/275185.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部