MouseCoord 函数, 是TCustomGrid 的都适用
这是我在 DBGrid 中判断是否在数据列中 dbl click mouse
{
TPoint Point;
TDBGrid *Grid = ( TDBGrid * )Sender; GetCursorPos( &Point );
Point = Grid->ScreenToClient( Point );
TGridCoord GridCoord = Grid->MouseCoord( Point.x, Point.y );
if ( GridCoord.Y != 0 ) // Y 就是行 X就是列
{
}
}
这是我在 DBGrid 中判断是否在数据列中 dbl click mouse
{
TPoint Point;
TDBGrid *Grid = ( TDBGrid * )Sender; GetCursorPos( &Point );
Point = Grid->ScreenToClient( Point );
TGridCoord GridCoord = Grid->MouseCoord( Point.x, Point.y );
if ( GridCoord.Y != 0 ) // Y 就是行 X就是列
{
}
}
有两个属性是 tstringgrid.row
tstringgrid.col
表示,光标所在位置,而且可以实现光标移动
我用的是STRINGGRID,你的程序不知是否管用吗?我等一下试试
肯定行,我就是这么用的。
记住,STRINGGRID 很强,很灵活,不同那么麻烦呀
我的问题是)。 比如一个CELLS的STRINGS是'abcdefg',
光标是在d和e 中间,我如何知道光标的位置。因为我想实现一个
功能是,比如当用户在对某一个CELLS中的值进行编辑,CELLS的值是'abcdefg',
而光标是在d和e之间,如果用户使用左移键,那么在STRINGGRID的缺省情况下
,光标是从d和e之间移动到c和d 之间, 问题是在当光标已经处于a之前,如果用户再使用左移键,那么我希望光标是
移动到前一个CELLS,也就是你说的COL + 1,我的问题就是怎么判断光标已经位于当前CELLS
的值的最前端了,然后我就可以COL + 1 了。
getcaretpos(p);
在click事件中如果editmode为true,GetCaretPos(p)得到光标位置lastx;
在keyup事件中
if not ?.editormode then exit;
GetCaretPos(p)
左键:
if p.x<lastx then begin lastx:=p.x;exit;end;
if p.x=lastx then ?.col:=?.col-1;
lastx:=p.x;
右键:
if p.x>lastx then begin lastx:=p.x;exit;end;
if p.x=lastx then ?.col:=?.col+1;
lastx:=p.x;试一下吧,至于移出左边界和右边界自己判断吧
p.x,p.y为光标到当前cell左上角的距离
先记录原来光标位置,再获得当前光标位置,如果x值相等,如左键col-1,右键col+1
谢谢你的帮助,我在试,如果有帮助我一定加分,我还有个
内容相同的帖子,你在那也留个言,到时,这个问题解决了,我分都给你。
To byrybye(BYRY) 回复于2001-9-26 10:27:21
没关系的,以后多联系。
那 lastx 的初始值是社麽呢?