🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
<p><br /> </p> <p><br /> </p> <p><strong><span style="font-size:16px;">HitTest 方法(</span></strong><span style="font-size:16px;"><strong>ListView </strong></span><strong><span style="font-size:16px;">和</span></strong><span style="font-size:16px;"><strong> TreeView </strong></span><strong><span style="font-size:16px;">控件)</span></strong></p> <p><span style="line-height:1.78571;">这个方法返回对位于</span><span style="line-height:1.78571;"> x </span><span style="line-height:1.78571;">和</span><span style="line-height:1.78571;"> y </span><span style="line-height:1.78571;">坐标的 </span><b>ListItem </b><span style="line-height:1.78571;">对象或 </span><b>Node </b><span style="line-height:1.78571;">对象的引用。通常与拖放操作一起使用,来确定放下的目标项在当前位置是否可用。</span></p> <span></span><p><br /> </p> <p class="label"><b>语法</b></p> <p><span class="emp"><i>object</i></span>.<b>HitTest</b> <b>(</b><span class="emp"><i>x</i></span> <b>As Single, </b><span class="emp"><i>y</i></span> <b>As Single)</b></p> <p><b>HitTest </b>方法的语法包含下面部分:<span></span></p> <table class="MsoNormalTable" border="1" cellpadding="0"><tbody><tr><td width="29%" valign="top"><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:宋体;">部分</span></b><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> <td width="71%" valign="top"><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:宋体;">描述</span></b><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> </tr> <tr><td width="29%" valign="top"><p class="MsoNormal"><span class="emp"><i><span style="font-size:9.0pt;">object</span></i></span><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> <td width="71%" valign="top"><p class="MsoNormal"><span style="font-size:9.0pt;font-family:宋体;"><span>对象表达式</span></span><span style="font-size:9.0pt;font-family:宋体;">,其值是<span>“</span>应用于<span>”</span>列表中的一个对象。</span><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> </tr> <tr><td width="29%" valign="top"><p class="MsoNormal"><span class="emp"><i><span style="font-size:9.0pt;">x,y</span></i></span><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> <td width="71%" valign="top"><p class="MsoNormal"><span style="font-size:9.0pt;font-family:宋体;">目标对象的坐标,它或是 <b><span>Node </span></b>对象,或是 <b><span>ListItem </span></b>对象。</span><span style="font-size:9.0pt;font-family:宋体;"></span></p> </td> </tr> </tbody> </table> <p class="MsoNormal">&nbsp;</p> <p class="label"><b>说明</b></p> <p>如果在指定的坐标没有对象,<b><span>HitTest </span></b>方法返回 <b><span>Nothing</span></b>。<span></span></p> <p><b>HitTest </b>方法常常与 <b><span>DropHighlight </span></b>属性一起使用来突出鼠标所指的对象。<b><span>DropHighlight </span></b>属性要求对指定要加亮的对象的引用。为了确定那个对象,<b><span>HitTest </span></b>方法与返回<span> x </span>和<span> y </span>坐标的事件(如<span> DragOver </span>事件)一起使用,如下所示:</p> <p><br /> </p> <pre class="prettyprint lang-vb">Private Sub TreeView1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) Set TreeView1.DropHighlight = TreeView1.HitTest(X,Y) End Sub</pre> <p><br /> </p> <p>在后面的<span> DragDrop </span>事件中使用 <b><span>DropHighlight </span></b>属性来返回对源控件最终落在其上的对象的引用,如以下代码所示:</p> <p><br /> </p> <pre class="prettyprint lang-vb">Private Sub TreeView1_DragDrop _ (Source As Control, x As Single, y As Single) 'DropHighlight 返回对其上发生放下的对象的引用。 Me.Caption = TreeView1.DropHighlight.Text '为了释放 DropHighlight 引用,设置它为 Nothing。 Set TreeView1.DropHighlight = Nothing End Sub</pre> <p><br /> </p> <p>注意在上面例子中,在过程完成之后,属性被设置为 <b><span>Nothing</span></b>。为了释放突出显示作用,必须这样做。<span></span></p> <p><br /> </p>