如何在用户单击鼠标之前单击并移动鼠标时阻止更改列表框选定项目

时间:2015-12-03 21:22:26

标签: livecode

我在滚动字段中使用以下代码。它在windows和android中都运行良好。唯一的问题是当鼠标在列表中上下移动时,所选项目会发生变化。我希望原始突出显示的行在滚动期间保持高亮显示,并且只有在鼠标没有移动时才会从初始垂直位置移动11个单位(行高为22)。如何修改此代码以实现该目标?

local lmousev,lvscroll,lscrolling

on mousedown

   --If we don't use lscrolling the list will scroll when the mouse hovers over it 
   put true into lscrolling

   --Set the initial vertical position of the cursor
   put the mousev into lmousev

   --Set the inital position of the vertical scroll
   put the dgvscroll of me into lvscroll 

end mousedown


on mousemove x,y

   if lscrolling=true then --lscrolling is only true after mousedown so no scroll when mouse hovers over

      --adjust the scroll position based on the vertical distance that the mouse has moved since mousedown
      set the dgvscroll of me to lvscroll -(y - lmousev)

   end if

end mousemove


on mouseUp

   --stop scrolling when mouse hovers
   put false into lscrolling


   If abs( the mousev-lmousev)<11 then --If vertival position of mouse has not moved far from vertical position at mousedown

      --selectlist command is in the group. It insert list selection into the textbox 
      selectlist

  end if

end mouseUp

on mouserelease

   --stop scrolling when mouse is release outside the listbox and there is no mouseup
   put false into lscrolling

end mouserelease

组成组合框的按钮,文本框和列表框被分组。显示/隐藏列表框并将所选内容添加到文本框的代码位于组脚本中,如下所示:

其他信息

local ldrop=false

on buttonclick --show/hide the listbox

   --Get the name of the group,textbox & listbox. 
   --Naming convention required:- textboxname=txt & groupName,listboxname=lst & groupname
   --Using quote as deliminater allows us to get the groupname from group "groupname"
   set the itemdel to quote
   put item 2 of the name of me into groupname
   put "lst" & groupname into lstName
   put "txt" & groupname into txtName

   --status of ldrop let us know if the listbox is visible
   if ldrop=false then

      --show listbox 
      set the visible of field lstName to true
      put true into ldrop

   else

       --hide listbox 
      set the visible of field lstName to false
      put false into ldrop

      end if

end buttonclick

on selectlist

   --Get the name of the group,textbox & listbox. 
   --Naming convention required:- textboxname=txt & groupName,listboxname=lst & groupname
   --Using quote as deliminater allows us to get the groupname from group "groupname"
   set the itemdel to quote
   put item 2 of the name of me into groupname
   put "lst" & groupname into lstName
   put "txt" & groupname into txtName


   put the hilitedLine of field lstName into lhilitedLine
   put line lhilitedLine of field lstName  into field txtName
   set the visible of field lstName to false
   put false into ldrop

end selectlist

1 个答案:

答案 0 :(得分:0)

我认为你必须自己创建一个像列表一样的控件,这样你就可以控制它发送和接收的所有消息。否则你会被LC的内置控件的一些基本功能所困扰。看起来你需要对控件进行引擎级调整。