.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C#实现主窗体工具栏上按钮两幅图片的交互效果

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

初次发文,敬请包涵。
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;
  }




相关文章

相关软件