发一个自己写的.NET CF 控件 ImageButton

开发环境:vs2005 beta2
测试环境:多普达696 Windows Mobile 2003 SE

ContractedBlock.gif ExpandedBlockStart.gif
 1None.gifusing System;
 2None.gifusing System.Drawing;
 3None.gif
 4None.gifpublic class ImageButton : System.Windows.Forms.Control
 5ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 6InBlock.gif    enum ButtonState
 7ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 8InBlock.gif        Normal,Mousedown
 9ExpandedSubBlockEnd.gif    }

10InBlock.gif
11InBlock.gif    private ButtonState m_ButtonState;
12InBlock.gif
13InBlock.gif public ImageButton()
14ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif{
15InBlock.gif        Text = "";
16InBlock.gif        Size = new Size(7225);
17InBlock.gif        m_ButtonState = ButtonState.Normal;
18ExpandedSubBlockEnd.gif }

19InBlock.gif
20InBlock.gif    private Image m_NormalImage;
21InBlock.gif    public Image NormalImage
22ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
23ExpandedSubBlockStart.gifContractedSubBlock.gif        get dot.gifreturn m_NormalImage; }
24InBlock.gif        set 
25ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
26InBlock.gif            m_NormalImage = value;
27InBlock.gif            if (value != null)
28ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
29InBlock.gif                Size = new Size(value.Width, value.Height);
30ExpandedSubBlockEnd.gif            }

31InBlock.gif            else
32ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
33InBlock.gif                Size = new Size(7225);
34ExpandedSubBlockEnd.gif            }

35ExpandedSubBlockEnd.gif        }

36ExpandedSubBlockEnd.gif    }

37InBlock.gif
38InBlock.gif    private Image m_MouseDownImage;
39InBlock.gif    public Image MouseDownImage
40ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
41ExpandedSubBlockStart.gifContractedSubBlock.gif        get dot.gifreturn m_MouseDownImage; }
42ExpandedSubBlockStart.gifContractedSubBlock.gif        set dot.gif{ m_MouseDownImage = value; }
43ExpandedSubBlockEnd.gif    }

44InBlock.gif
45InBlock.gif    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
46ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{        
47InBlock.gif        if (m_ButtonState == ButtonState.Normal)
48ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
49InBlock.gif            if (NormalImage != null)
50ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{                
51InBlock.gif                e.Graphics.DrawImage(NormalImage, new Rectangle(00, Width, Height), new Rectangle(00, NormalImage.Width, NormalImage.Height),GraphicsUnit.Pixel);
52ExpandedSubBlockEnd.gif            }
       
53ExpandedSubBlockEnd.gif        }

54InBlock.gif        else if (m_ButtonState == ButtonState.Mousedown)
55ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
56InBlock.gif            if (MouseDownImage != null)
57ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
58InBlock.gif                e.Graphics.DrawImage(MouseDownImage, new Rectangle(00, Width, Height), new Rectangle(00, MouseDownImage.Width, MouseDownImage.Height), GraphicsUnit.Pixel);
59ExpandedSubBlockEnd.gif            }

60InBlock.gif            else if (NormalImage != null)
61ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
62InBlock.gif                e.Graphics.DrawImage(NormalImage, new Rectangle(00, Width, Height), new Rectangle(00, NormalImage.Width, NormalImage.Height), GraphicsUnit.Pixel);
63ExpandedSubBlockEnd.gif            }
  
64ExpandedSubBlockEnd.gif        }

65InBlock.gif        StringFormat sf = new StringFormat();
66InBlock.gif        sf.Alignment = StringAlignment.Center;
67InBlock.gif        sf.LineAlignment = StringAlignment.Center;
68InBlock.gif        e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(00, Width, Height), sf);
69ExpandedSubBlockEnd.gif    }

70InBlock.gif
71InBlock.gif    protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
72ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
73InBlock.gif        m_ButtonState = ButtonState.Mousedown;
74InBlock.gif        Refresh();
75ExpandedSubBlockEnd.gif    }

76InBlock.gif
77InBlock.gif    protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
78ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
79InBlock.gif        m_ButtonState = ButtonState.Normal;
80InBlock.gif        Refresh();
81ExpandedSubBlockEnd.gif    }

82ExpandedBlockEnd.gif}

83None.gif
84None.gif


设计效果图
ImageButtonDesigh.JPG


另外问一句都谁把696升级成了WM5.0了?我也想升一下试试,指教一下

转载于:https://www.cnblogs.com/mobile/archive/2005/10/10/251994.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值