• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

C#实现主窗体工具栏上按钮两幅图片的交互效果

发布: 2007-6-30 23:38 | 作者: admin | 来源: | 查看: 67次 | 进入软件测试论坛讨论

领测软件测试网 初次发文,敬请包涵。
using System.Runtime.InteropServices;
窗口类添加以下成员或函数
private static int buttonIndex;
[DllImport("User32", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, uint wParam, ref Point lParam);
public const int TB_HITTEST = 1093;
//本例为四个按钮(注意:当添加属性style为separator的按钮后要作相应的变化)
//添加一个ImageList控件ImageList1(添加八个图片依次为0...7,顺序不能变,
//注意交互时图片0,1,2,3分别对应图片4,5,6,7)
//添加一个ToolBar控件ToolBar1(其ImageList属性为ImageList1,
//四个按钮的imageindex分别为0,1,2,3)

//工具栏MouseMove事件
private void toolBar1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
IntPtr result =
SendMessage(this.toolBar1.Handle, TB_HITTEST, 0, ref pt);
buttonIndex = result.ToInt32();
const int lowBtnIndex = 0;
const int highBtnIndex =3;
if((buttonIndex >= lowBtnIndex ) && (buttonIndex <= highBtnIndex))
{
for(int u=0;u<4;u++)
{
if(u==buttonIndex)
this.toolBar1.Buttons[buttonIndex].ImageIndex=4+buttonIndex;
else
this.toolBar1.Buttons[u].ImageIndex=u;
}
}
else
{
for(int u=0;u<4;u++)
this.toolBar1.Buttons[u].ImageIndex=u;
}
}

//工具栏MouseLeave事件
private void toolBar1_MouseLeave(object sender, System.EventArgs e)
{
if((buttonIndex >= 0) && (buttonIndex <=3))
{
this.toolBar1.Buttons[buttonIndex].ImageIndex=buttonIndex;
}
buttonIndex=4;
}



延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网