改动鼠标形状的一小段代码

主要还是调用了系统的方法,因为实在做鼠标时间是开发的,想了好久才找到,留在这里,以作纪念。

 public class Grid : GoldSoft.Inf.UI.Controls.Grid.Grid
 {
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;
 
  public Grid()
  {
   // 该调用是 Windows.Forms 窗体设计器所必需的。
   InitializeComponent();
   // TODO: 在 InitComponent 调用后添加任何初始化
         this.MouseMove += new MouseEventHandler(n_MouseMove);   
  }
  private void n_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  {   
         this.Cursor=Cursors.SizeWE;

     //以上用来修改鼠标的形状,在Cursors加.就可以看到了
         Console.WriteLine("====>   Test  <====  ("+e.X+","+e.Y+")");   
  }
  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if( components != null )
     components.Dispose();
   }
   base.Dispose( disposing );
  }

  #region 组件设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器
  /// 修改此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   components = new System.ComponentModel.Container();
  }
  #endregion

 }

因为编写改代码是要完成用鼠标拖动线,现在能够通过计算,来找到线的位置:

GridCell [] cell = ZGridCells;
   
   int[] m_col=ZAllCols;            //这里存储一个表格中每个单元格长度
   int[] m_row=ZAllRows;         //这里存储一个表格中每个单元格高度
   bool mx_flag = false;            //注意这两个bool的用法
   bool my_flag = false;
   int x=e.X;                                   //获取鼠标当前的x,y的值
   int y=e.Y;
   int s=0;              

    //这里只是进行了最简单的判断,有很大的算法问题,会影响效率,暂时就这样了,先求实现,后改效率
   for(int i=0;i<m_col.Length;i++)
   {
    s+=m_col[i];
    if ( x==s-1 || x==s || x==s+1 )
    {
     mx_flag=true;
     break;
    }
   }
   s=0;
   for(int i=0;i<m_row.Length;i++)
   {
    s+=m_row[i];
    if ( y==s-1 || y==s || y==s+1 )
    {
     my_flag=true;
     break;
    }
   }

    //一旦出现鼠标停在横竖线的交叉口上,看看会出什么效果
   if (!mx_flag && !my_flag)
    this.Cursor=Cursors.Default;
   else if(mx_flag)
    this.Cursor=Cursors.SizeWE;
   else if(my_flag)
    this.Cursor=Cursors.SizeNS; 

    //对了,会选择这一条this.Cursor=Cursors.SizeWE;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值