鼠标滚动轮事件

taohua300 2011-12-02 03:13:01

1. 当鼠标在表单内的控件上时

滚动鼠标滚动轮

如何使表单上下滚动

2. 如何判断光标是否“在表单中”

如果一个表单中有很多控件

光标在最下面的一个文本控件中

但由于滚动条没有滚动

造成表面上看上去光标没有在表单中

(真啰嗦,不知道怎么表达)

换句话说就是如何判断光标不在表单是显示区域中
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
十豆三 2011-12-04
  • 打赏
  • 举报
回复
我在XP下是有区别的,vfp版本和你的相同。
taohua300 2011-12-03
  • 打赏
  • 举报
回复
我在win7 下 vfp 9.0 sp2 7423

不管是0或3

thisform.viewportwidth 返回的都是foxels值

如果从工具-选项-表单-度量工具中改成foxels,则

不管表单ScaleMode是0或3

thisform.viewportwidth 返回是却又是像素值
十豆三 2011-12-03
  • 打赏
  • 举报
回复
表单是ScaleMode设置为0或3是有区别的
taohua300 2011-12-03
  • 打赏
  • 举报
回复
豆老师

表单的foxels和像素是怎么转换的?

我刚才试了一下

不管表单是ScaleMode设置为0还是3

messagebox(thisform.viewportwidth)

返回的都是foxels值

但我现在的表单都是按默认的像素

如果这样来判断光标是否在“当前显示”中

数值上会不对应
taohua300 2011-12-03
  • 打赏
  • 举报
回复
神了
十豆三 2011-12-03
  • 打赏
  • 举报
回复
*-- 为了测试,在表单添加了多种控件
*-- 主要代码在自定义方法 mymousewheel、setmousewheel 和 Init 事件中。

Public oform1
oform1=Newobject("form1")
oform1.Show
Return

Define Class form1 As Form

Top = 0
Left = 0
Height = 342
Width = 420
ScrollBars = 3
DoCreate = .T.
Caption = "Form1"
KeyPreview = .T.
WindowState = 0
ContinuousScroll = .F.
Name = "Form1"

Add Object command1 As CommandButton With ;
Top = 312, ;
Left = 384, ;
Height = 25, ;
Width = 60, ;
Caption = "Command1", ;
Name = "Command1"

Add Object text1 As TextBox With ;
Height = 20, ;
Left = 432, ;
Top = 336, ;
Width = 100, ;
Name = "Text1"

Add Object label1 As Label With ;
Caption = "Label1", ;
Height = 16, ;
Left = 516, ;
Top = 384, ;
Width = 38, ;
Name = "Label1"

Add Object command2 As CommandButton With ;
Top = 12, ;
Left = 336, ;
Height = 25, ;
Width = 60, ;
Caption = "Command2", ;
Name = "Command2"

Add Object grid1 As Grid With ;
Height = 116, ;
Left = 216, ;
Top = 48, ;
Width = 176, ;
Name = "Grid1"

Add Object shape1 As Shape With ;
Top = 0, ;
Left = 12, ;
Height = 372, ;
Width = 109, ;
Name = "Shape1"

Add Object command3 As CommandButton With ;
Top = 120, ;
Left = 144, ;
Height = 25, ;
Width = 60, ;
Caption = "Command3", ;
Name = "Command3"

Add Object container1 As Container With ;
Top = 192, ;
Left = 156, ;
Width = 156, ;
Height = 116, ;
Name = "Container1"

Procedure container1.Init
This.AddObject('Pageframe1','Pageframe')
This.Pageframe1.Move(24,12,121,85)
This.Pageframe1.PageCount=2
This.Pageframe1.page1.AddObject('Command1','CommandButton')
This.Pageframe1.page1.Command1.Move(23,22,60,25)
This.Pageframe1.Visible=.T.
This.Pageframe1.page1.Command1.Visible=.T.
Endproc

Procedure mymousewheel
Lparameters nDirection, nShift, nXCoord, nYCoord
Thisform.SetViewPort(Thisform.ViewPortLeft,Max(Thisform.ViewPortTop-Iif(nDirection>0,1,-1),0))
Nodefault && 鼠标在 表格、容器、页框中滚动均有效果,但当鼠标焦点在 表格 中时,会同时触发 表格 的滚动事件,所以要加此句来不执行原默认事件。
Endproc

Procedure setmousewheel
Lparameters toControl
If Pemstatus(toControl,"MouseWheel",5)
=Bindevent(toControl,"MouseWheel",This,"MyMouseWheel")
Endif
If Type("toControl.Objects[1]")="O"
Local loI
For Each loI In toControl.Objects
This.SetMouseWheel(loI)
Endfor
Endif
Endproc

Procedure Init
This.ScaleMode=0
This.SetMouseWheel(Thisform)
Endproc

Procedure Load
Create Cursor t1 (a1 i)
For lnI=1 To 20
Insert Into t1 Values (lnI)
Endfor
Locate
Endproc

Enddefine
taohua300 2011-12-02
  • 打赏
  • 举报
回复
是的

如果鼠标指针在表单中 表单是能响应鼠标滚动轮事件的

但是如果鼠标在text1中,表单就不能滚动了 (鼠标指针放在text1上)

十豆三 2011-12-02
  • 打赏
  • 举报
回复
当表单是焦点窗口时,你滚动鼠标滚轮,表单会自动响应的,你运行以下代码,然后滚动鼠标滚轮就知道了。
Public oform1

oform1=Newobject("form1")
oform1.Show
Return

Define Class form1 As Form

Top = 0
Left = 0
Height = 252
Width = 360
ScrollBars = 3
DoCreate = .T.
Caption = "Form1"
Name = "Form1"

Add Object command1 As CommandButton With ;
Top = 312, ;
Left = 384, ;
Height = 25, ;
Width = 60, ;
Caption = "Command1", ;
Name = "Command1"

Add Object text1 As TextBox With ;
Height = 20, ;
Left = 432, ;
Top = 336, ;
Width = 100, ;
Name = "Text1"

Enddefine

2,728

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧