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下的情况 ...
随机推荐
- [译]Stairway to Integration Services Level 7 - SSIS 工作流管理中级
介绍 前一个章节我们对SSIS的优先约束做了初步了解,并且实验了MaxConcurrentExecutables 包属性的设置. 本文将测试“On Success”, “On Completion”, ...
- C# Best Practices - Creating Good Methods
How to Define a Method Identify the problem => Define the single purpose => Specify the inputs ...
- json与字符串互转
1 字符串转JSON var obj=eval('('+str+")') var obj=JSON.parse(str) var obj=str.parseJSON() 2 JSON转字符串 ...
- 服务器忘记mysql密码怎么修改?
找到配置文件my.ini ,然后将其打开,可以选择用记事本打开 打开后,搜索mysqld关键字 找到后,在mysqld下面添加skip-grant-tables,保存退出. PS:若提示不让保存时, ...
- 在 Windows Azure 网站 (WAWS) 上对 Orchard CMS 使用 Azure 缓存
编辑人员注释: 本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 撰写. 如果您当前的 OrchardCMS 网站在 Windows Azure 网站 ...
- 基于visual Studio2013解决C语言竞赛题之0302字符数出
题目 解决代码及点评 根据题目要求,只要根据用户输入的字母,判断字母之后,给出相应的输出即可 在以下代码中,f32函数实现了该功能,通过if条件判断语句 #include <stdio.h ...
- 在不连接网线的情况下Windos与VM之间如何ping通
一般情况下,如果宿主主机的网口连接网线并且能够上网,那么按照VM的默认安装,在VM-Settings-Hardware-Network Adapter-Network connection中选择Bri ...
- git 使用过程(二、创建版本库)
1.显示当前git所在操作文件路径 命令:pwd 2.改变当前操作路径 命令:cd /e/神马神马的,如果想到当前文件夹的某个子目录下,可以直接输入命令:cd 子目录名称,这样就可以了. 3.创建一 ...
- WAMP多站点配置,更改服务器端口
修改apache.conf的配置文件 设置保存路径 原本的路径:DocumentRoot "D:/wamp/www/" 修改为自己定义的路径:D:\all_code\php 查询: ...
- 【Web】HttpServletRequest request 相关方法 得到路径
username=qqqq password=wwww //----------------------POST-------------------> http://192.168.1.211 ...