Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何在控件中开启/关闭拖放移动事件

From Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台安全性
需要的签名: Self-Signed
能力: None

文章
翻译:
hoolee
最后由 hamishwillee 在 22 Dec 2011 编辑

Contents

概述

下列代码演示了如何让控件接受拖放触摸事件。

缺省的,点拖放事件和点移动事件没有发送到控件中。缺省情况下,当一个窗口生成后的移动,拖动,进入和退出事件,是不会传递到client的,为了让控件能够接收到这些,我们需要在控件构造的环节呼叫EnableDragEvents(),之后,控件就可以调用 HandlePointerEventL()来接收拖动事件。


前提

我们假设这里为一个UI界面的应用程序

MMP file

需要下列能力和链接库:

CAPABILITY None

LIBRARY cone.lib

include <COECNTRL.H>

允许拖放和移动事件

void CSomeAppView::ConstructL(const TRect& aRect)
{
// Create a window for the container
CreateWindowL();
.
. .
. . .
// Enable Drag Events.
EnableDragEvents();
 
// OR can also be done with
Window().PointerFilter(EPointerFilterDrag, 0);
 
.. ..
}

处理拖放和移动事件

HandlePointerEventL()方法中,控件接收到拖移事件通知,我们可以在这里进行相关处理

void CSomeAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
switch (aPointerEvent.iType)
{
.
. .
. . .
case TPointerEvent::EDrag:
{
// Handle drag event here.
break;
}
case TPointerEvent::EMove:
{
// Handle move event here.
break;
}
default:
{
// do something
break;
}
}


取消拖放和移动事件

这个控件没有提供函数来关闭这些事件,但我们可以通过Window Server API来完成,可以调用Window()->PointerFilter()方法来处理

// A 1 bit causes the corresponding event to be filtered out, a 0 bit lets through the corresponding event. 
Window().PointerFilter(EPointerFilterDrag, 1);

后记

拖放和移动事件将被开启和关闭

This page was last modified on 22 December 2011, at 05:01.
50 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×