Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Evento ToolStripItem.DragLeave

 

Data di pubblicazione: ottobre 2016

Si verifica quando l'utente trascina un elemento e il puntatore del mouse non è più posizionato sull'area client di questo elemento.

Spazio dei nomi:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public event EventHandler DragLeave

The E:System.Windows.Forms.ToolStripItem.DragLeave event is raised when the user drags the cursor out of the control or the user cancels the current drag-and-drop operation.

The following remarks describe how and when events related to drag-and-drop operations are raised.

The M:System.Windows.Forms.ToolStripItem.DoDragDrop(System.Object,System.Windows.Forms.DragDropEffects) method determines the item under the current cursor location. It then checks to see if the item is a valid drop target.

If the item is a valid drop target, the E:System.Windows.Forms.ToolStripItem.GiveFeedback event is raised with the drag-and-drop effect specified. For a list of drag-and-drop effects, see the T:System.Windows.Forms.DragDropEffects enumeration.

Changes in the mouse cursor position, keyboard state, and mouse button state are tracked in the following manner:

  • If the user moves out of a window, the E:System.Windows.Forms.ToolStripItem.DragLeave event is raised.

  • If the mouse enters another item, the E:System.Windows.Forms.ToolStripItem.DragEnter for that control is raised.

  • If the mouse moves but stays within the same item, the E:System.Windows.Forms.ToolStripItem.DragOver event is raised.

If there is a change in the keyboard or mouse button state, the E:System.Windows.Forms.ToolStripItem.QueryContinueDrag event is raised and determines whether to continue the drag, to drop the data, or to cancel the operation based on the value of the P:System.Windows.Forms.QueryContinueDragEventArgs.Action property of the event's T:System.Windows.Forms.QueryContinueDragEventArgs.

If the value of T:System.Windows.Forms.DragAction is F:System.Windows.Forms.DragAction.Continue, the E:System.Windows.Forms.ToolStripItem.DragOver event is raised to continue the operation and the E:System.Windows.Forms.ToolStripItem.GiveFeedback event is raised with the new effect so appropriate visual feedback can be set. For a list of valid drop effects, see the T:System.Windows.Forms.DragDropEffects enumeration.

The E:System.Windows.Forms.ToolStripItem.DragOver and E:System.Windows.Forms.ToolStripItem.GiveFeedback events are paired so that as the mouse moves across the drop target, the user is given the most up-to-date feedback on the mouse's position, as follows:

  • If the value of T:System.Windows.Forms.DragAction is F:System.Windows.Forms.DragAction.Drop, the drop effect value is returned to the source, so the source application can perform the appropriate operation on the source data; for example, cut the data if the operation was a move.

  • If the value of T:System.Windows.Forms.DragAction is F:System.Windows.Forms.DragAction.Cancel, the E:System.Windows.Forms.ToolStripItem.DragLeave event is raised.

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the E:System.Windows.Forms.ToolStripItem.DragLeave event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing Overload:System.Windows.Forms.MessageBox.Show with Overload:System.Console.WriteLine or appending the message to a multiline T:System.Windows.Forms.TextBox.

To run the example code, paste it into a project that contains an instance of a type that inherits from T:System.Windows.Forms.ToolStripItem, such as a T:System.Windows.Forms.ToolStripButton or T:System.Windows.Forms.ToolStripMenuItem. Then name the instance ToolStripItem1 and ensure that the event handler is associated with the E:System.Windows.Forms.ToolStripItem.DragLeave event.

private void ToolStripItem1_DragLeave(Object sender, EventArgs e) {

   MessageBox.Show("You are in the ToolStripItem.DragLeave event.");

}

.NET Framework
Disponibile da 2.0
Torna all'inizio
Mostra: