Share via


GiveFeedbackEventArgs.UseDefaultCursors 属性

获取或设置拖动操作是否应使用与拖放效果关联的默认光标。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property UseDefaultCursors As Boolean
用法
Dim instance As GiveFeedbackEventArgs
Dim value As Boolean

value = instance.UseDefaultCursors

instance.UseDefaultCursors = value
public bool UseDefaultCursors { get; set; }
public:
property bool UseDefaultCursors {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_UseDefaultCursors ()

/** @property */
public void set_UseDefaultCursors (boolean value)
public function get UseDefaultCursors () : boolean

public function set UseDefaultCursors (value : boolean)

属性值

如果使用默认指针,值为 true;否则值为 false

备注

对于其他不同的拖放操作(如移动或复制),系统会提供默认的拖放光标。如果 UseDefaultCursors 设置为 false,则由事件源来设置合适的光标。

示例

下面的示例演示了在两个 ListBox 控件间的拖放操作。当拖动动作启动时,该示例调用 DoDragDrop 方法。在 MouseDown 事件期间,如果从鼠标位置起鼠标移动的距离大于 SystemInformation.DragSize,则启动拖动动作。IndexFromPoint 方法用于在 MouseDown 事件期间确定要拖动的项的索引。

该示例同时演示了对拖放操作使用自定义光标。示例假定应用程序目录中存在两个光标文件:3dwarro.cur3dwno.cur,分别用于自定义拖动光标和禁止停放光标。如果选中 UseCustomCursorsCheckCheckBox,则使用自定义光标。自定义光标在 GiveFeedback 事件处理程序中设置。

键盘状态在右 ListBoxDragOver 事件处理程序中计算,以根据 Shift、Ctrl、Alt 或 Ctrl+Alt 键的状态确定将发生哪种拖动操作。放置动作在 ListBox 中发生的位置也在 DragOver 事件期间确定。如果要放置的数据不是一个 String,则 DragEventArgs.Effect 将被设置为 DragDropEffects.None。最后,停放状态在 DropLocationLabelLabel 中显示。

要放置的用于右 ListBox 的数据在 DragDrop 事件处理程序中确定,并且在 ListBox 中的适当位置添加该 String 值。如果拖动操作移动到窗体边框的外面,则 QueryContinueDrag 事件处理程序中将取消拖放操作。

这段代码摘录演示了 GiveFeedbackEventArgs 类的用法。有关完整的代码实例,请参见 DoDragDrop 方法。

Private Sub ListDragSource_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListDragSource.GiveFeedback

    ' Use custom cursors if the check box is checked.
    If (UseCustomCursorsCheck.Checked) Then

        ' Set the custom cursor based upon the effect.
        e.UseDefaultCursors = False
        If ((e.Effect And DragDropEffects.Move) = DragDropEffects.Move) Then
            Cursor.Current = MyNormalCursor
        Else
            Cursor.Current = MyNoDropCursor
        End If
    End If

End Sub
private void ListDragSource_GiveFeedback(object sender, System.Windows.Forms.GiveFeedbackEventArgs e) 
{
    // Use custom cursors if the check box is checked.
    if (UseCustomCursorsCheck.Checked) {

        // Sets the custom cursor based upon the effect.
        e.UseDefaultCursors = false;
        if ((e.Effect & DragDropEffects.Move) == DragDropEffects.Move)
            Cursor.Current = MyNormalCursor;
        else 
            Cursor.Current = MyNoDropCursor;
    }

}
void ListDragSource_GiveFeedback( Object^ /*sender*/, System::Windows::Forms::GiveFeedbackEventArgs^ e )
{
   // Use custom cursors if the check box is checked.
   if ( UseCustomCursorsCheck->Checked )
   {
      // Sets the custom cursor based upon the effect.
      e->UseDefaultCursors = false;
      if ( (e->Effect & DragDropEffects::Move) == DragDropEffects::Move )
                  ::Cursor::Current = MyNormalCursor;
      else
                  ::Cursor::Current = MyNoDropCursor;
   }
}
private void listDragSource_GiveFeedback(Object sender, 
    System.Windows.Forms.GiveFeedbackEventArgs e)
{
    // Use custom cursors if the check box is checked.
    if (useCustomCursorsCheck.get_Checked()) {
        // Sets the custom cursor based upon the effect.
        e.set_UseDefaultCursors(false);
        if ((e.get_Effect() & DragDropEffects.Move) 
            == DragDropEffects.Move) {
            get_Cursor().set_Current(myNormalCursor);
        }
        else {
            get_Cursor().set_Current(myNoDropCursor);
        }
    }
} //listDragSource_GiveFeedback

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

GiveFeedbackEventArgs 类
GiveFeedbackEventArgs 成员
System.Windows.Forms 命名空间