如何将光标属性设置为DataGridViewComboBoxColumn? [英] How To Set The Cursor Property To DataGridViewComboBoxColumn?

查看:117
本文介绍了如何将光标属性设置为DataGridViewComboBoxColumn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是VS2010。我在DataGridView中有一个DataGridViewComboBoxColumn。我希望将光标设置为该列,是否可以?



Hi, Iam using VS2010. I have a DataGridViewComboBoxColumn in DataGridView. I wish to set the cursor to that column, Is it possible?

MyDGVComboBoxColumn.Cursor = Cursors.Hand;





谢谢



Thanks

推荐答案

你不能直接这样做,因为<$ c的列$ c> DataGridView 不是控件。您可以尝试通过修改此控件的属性 Cursor 来实现所需的效果,具体取决于带控件的鼠标的当前位置,使用列宽来计算每个控件的位置列。您可以通过处理控件的事件 MouseMove 来处理鼠标位置的变化。



请参阅:

http://msdn.microsoft.com /en-us/library/vstudio/system.windows.forms.control.cursor [ ^ ],

http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.mousemove [< a href =http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.mousemovetarget =_ blanktitle =New Window> ^ ] 。



另一种更简单,更有效的方法是处理事件 CellMouseEnter CellMouseLeave 。这样,您可以捕获将鼠标光标从一个单元移动到单元格,并分析单元属性的值 DataGridViewCell.ColumnIndex 为上一个和当前单元格,可以判断您是否要离开或进入相关列。当捕获到这样的跨越列边界的事件时,您可以再次使用属性 DataGridView.Cursor 来更改光标外观。



http://msdn.microsoft.com/ en-us / library / vstudio / system.windows.forms.datagridview.cellmouseenter [ ^ ],

http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseleave [<一个href =http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseleavetarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.columnindex(V = vs.110)的.aspx [ ^ ]。



我认为这些说明很清楚,你只需要实现它们。



-SA
You cannot directly do it, because columns of the DataGridView are not controls. You can try to achieve desired effect by modifying the property Cursor of this control, depending on the current location of the mouse withing the control, using columns widths to calculate the location of each columns. You can handle the change in mouse location by handling the event MouseMove of the control.

Please see:
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.cursor[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.mousemove[^].

Another, perhaps simpler and more efficient approach would be handling the events CellMouseEnter and CellMouseLeave. This way, you can capture moving your mouse cursor from cell to cell and, analyzing the values of the cell property DataGridViewCell.ColumnIndex for "previous" and "current" cell, you can figure out if you are leaving or entering the column in question. When such event of crossing of the column boundary is captured, you can again use the property DataGridView.Cursor to change the cursor appearance.

http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseenter[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.datagridview.cellmouseleave[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.columnindex(v=vs.110).aspx[^].

I think those instructions are quite clear, you just have to implement them.

—SA


这篇关于如何将光标属性设置为DataGridViewComboBoxColumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆