Wince下实现ImageButton
我们在winform中给按钮设置个背景图片超级简单,是不?可是在wince下面就没那么简单了,下面我来介绍一种方式来实现ImageButton。
实现思路是重新写一个usercontrol就ok。具体的实现方式如下:
/IotButton是我们新控件的名字,具体的可以自己定义
public partial class IotButton : UserControl
{
public IotButton()
{
InitializeComponent();
} Image backgroundImage;
bool pressed = false; // Property for the background image to be drawn behind the button text.
public Image BackgroundImage
{
get
{
return this.backgroundImage;
}
set
{
this.backgroundImage = value;
}
}
// When the mouse button is pressed, set the "pressed" flag to true
// and invalidate the form to cause a repaint. The .NET Compact Framework
// sets the mouse capture automatically.
protected override void OnMouseDown(MouseEventArgs e)
{
this.pressed = true;
this.Invalidate();
base.OnMouseDown(e);
} // When the mouse is released, reset the "pressed" flag
// and invalidate to redraw the button in the unpressed state.
protected override void OnMouseUp(MouseEventArgs e)
{
this.pressed = false;
this.Invalidate();
base.OnMouseUp(e);
} // Override the OnPaint method to draw the background image and the text.
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(SystemColors.ActiveCaption), e.ClipRectangle); if (this.backgroundImage != null)
{
ImageAttributes attr = new ImageAttributes();
attr.SetColorKey(Color.Magenta, Color.Magenta); if (this.pressed)
e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, 0, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr);
else
e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, 0, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr); } base.OnPaint(e);
}
}
这里为什么要实现一个新的UserControl而不是基于Button呢?具体原因是这样的,因为Button中没有Paint事件,没有MouseUP MouseDown MouseMove等事件因此不能很好的实现,有图有证据哦?
看看我们自定义的按钮的事件和属性吧:
总结
上面的方式实现了在wince下自定义一个可以放image的控件,具体的不同我们可以对比上面的两图得到。希望对大家有帮助哦。
Wince下实现ImageButton的更多相关文章
- WinCE下读取注册表获得SD路径
WinCE下读取注册表获得SD路径 [要点]WinCE注册表中[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory\] 下键Folde ...
- WinCE下GPRS自动拨号软件(GPRS AutoDial)
之前在WinCE下调试USB的3G Modem时,写过一个拨号助手RASManager,基本能用.后来车机卖到俄罗斯去,客户老M提供了一个更好的GPRS自动拨号软件GPRS AutoDial,功能完善 ...
- Wince下sqlce数据库开发(二)
上次写到使用数据绑定的方法测试本地sqlce数据库,这次使用访问SQL Server的方法访问sqlce,你会发现他们是如此的相似... 参考资料:http://www.cnblogs.com/rai ...
- Wince下sqlce数据库开发(一)
对于Wince下的sqlce数据库虽然很多人在用,但在我查找资料时,却发现资料是多么的匮乏,在此对自己这几天的了解做个简单介绍,希望对大家能有所帮助! 本文的最后附有所使用到的sqlce在wince下 ...
- 在Window Embedded CE(Wince)下使用OpenNETCF进行路由表的开发
点击打开链接 背景 在开发3G项目的是时候,发现尽管3G网络连接已经建立成功了,但是数据不能发送成功,查明原因,由于路由表的问题,导致数据往ActiveSync连接的对端,也就是PC发送,而不是发送到 ...
- WinCE下使用C#获得带毫秒的DateTime.Now
在WinCE下,使用DateTime.Now获取的系统时间是不带毫秒的,如果想要它带毫秒,需要耍点手段.话不多说,直接上代码: public static DateTimePrecisely { // ...
- wince下sources\sources.cmn\Makefile.def的相关作用
1:首先是Makefile.def: ---------------------------------------- 在所有驱动的makefile中有!INCLUDE $(_MAKEENVROOT) ...
- SD card技术了解并WINCE下SDHC驱动开发(updated)
Suumary: 简单介绍了一下SD卡的历史和发展,同时结合MX31 ADS上的WINCE 下SDHC驱动更深入的了解该硬件的一些行为特点. 了解SD card SD是Secure Digital C ...
- 如何捕获Wince下form程序的全局异常
前言 上两篇文章我们总结了在winform程序下如何捕获全局的异常.那么同样的问题,在wince下我们如何来处理呢?用相同的代码来处理可以吗? 答案是否定的,上面的方案1完全不能解决wince下的情况 ...
随机推荐
- SQL Server(SSIS package) call .net DLL
There are two method to call .net DLL in SQLSERVER. The first one is to use the sql clr but it has a ...
- ASP.net体系
- C#中泛型、程序集一些基本运用(Fifteenth Day)
今天主要在学习了泛型和程序集以及一些细碎的知识的运用.下面我就把今天所学的总结一下. 理论: 泛型: * 英文名字是Generic,可以让多个类型共享一组代码,泛型允许我们声明类型参数化,可以用不同的 ...
- Python IDLE快捷键
编辑状态时:Ctrl + [ .Ctrl + ] 缩进代码Alt+3 Alt+4 注释.取消注释代码行Alt+5 Alt+6 切换缩进方式 空格<=>TabAlt+/ 单词完成,只要文中出 ...
- Mac上使用Visual Studio Code开发/调试.NET Core代码
Mac上使用Visual Studio Code开发/调试.NET Core代码 .Net Core 1.0终于发布了,Core的一大卖点就是跨平台.这个跨平台不只是跨平台运行,而且可以跨平台开发.今 ...
- 转:按需加载html 图片 css js
按需加载是前端性能优化中的一项重要措施,按需加载是如何定义的呢?顾名思义,指的是当用户触发了动作时才加载对应的功能.触发的动作,是要看具体的业务场景而言,包括但不限于以下几个情况:鼠标点击.输入文字. ...
- Qt在各平台上的搭建qt-everywhere
Qt for windows7-64bit 在电脑上安装mingw(搜索mingw for windows),将C:\MinGW\bin添加进环境变量,打开命令行输入gcc --version和g++ ...
- android -- 蓝牙 bluetooth (四)OPP文件传输
在前面android -- 蓝牙 bluetooth (一) 入门文章结尾中提到了会按四个方面来写这系列的文章,前面已写了蓝牙打开和蓝牙搜索,这次一起来看下蓝牙文件分享的流程,也就是蓝牙应用opp目录 ...
- EBS 数据库预克隆日志
ora02@[/u07/CCTEST02/db/tech_st/11.1.0/appsutil/scripts/CCTEST02_test01] $ T02_test01/StageDBTier_06 ...
- window下如何搭建linux环境
1.使用虚拟机 使用VMware虚拟机,下载linux内核系统,加载运行. 2.cygwin 安装cygwin,设置环境变量. 第二种方法还是比较简便的.优先考虑.