Handling the DragEnter Event in VS .NET

Encoder QR Code JIS X 0510 in VS .NET Handling the DragEnter Event

Handling the DragEnter Event
QR Code ISO/IEC18004 Drawer In VS .NET
Using Barcode maker for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Bar Code Creation In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create bar code image in ASP.NET applications.
www.OnBarcode.com
The DragEnter event should be handled for every target control. This event occurs when a drag-and-drop operation is in progress and the mouse pointer enters the con trol. This event passes a DragEventArgs object to the method that handles it, and you can use the DragEventArgs object to query the DataObject associated with the dragand-drop operation. If the data is appropriate for the target control, you can set the Effect property to an appropriate value for the control. The following example demon strates how to examine the data format of the DataObject and set the Effect property.
QR-Code Generator In C#
Using Barcode encoder for .NET Control to generate, create Denso QR Bar Code image in .NET applications.
www.OnBarcode.com
Denso QR Bar Code Printer In VS .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create Denso QR Bar Code image in .NET framework applications.
www.OnBarcode.com
' VB Private Sub TextBox2_DragEnter(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter If e.Data.GetDataPresent(DataFormats.Text) = True Then e.Effect = DragDropEffects.Copy End If End Sub
QR Code JIS X 0510 Printer In Visual Basic .NET
Using Barcode creation for VS .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications.
www.OnBarcode.com
Encoding UPC Symbol In VS .NET
Using Barcode printer for ASP.NET Control to generate, create UCC - 12 image in ASP.NET applications.
www.OnBarcode.com
Lesson 1: Implementing Drag-and-Drop Functionality
ECC200 Creator In Visual Studio .NET
Using Barcode generator for ASP.NET Control to generate, create Data Matrix ECC200 image in ASP.NET applications.
www.OnBarcode.com
Print Barcode In .NET
Using Barcode creation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
www.OnBarcode.com
// C# private void textBox2_DragEnter (object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) { e.Effect = DragDropEffects.Copy; } }
Generate Code 39 Extended In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
www.OnBarcode.com
Bar Code Creator In VS .NET
Using Barcode creation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
www.OnBarcode.com
Handling the DragDrop Event
QR Code ISO/IEC18004 Encoder In .NET
Using Barcode encoder for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Make USPS PLANET Barcode In .NET Framework
Using Barcode creation for ASP.NET Control to generate, create USPS PLANET Barcode image in ASP.NET applications.
www.OnBarcode.com
When the mouse button is released over a target control during a drag-and-drop oper ation, the DragDrop event is raised. In the method that handles the DragDrop event, you can use the GetData method of the DataObject to retrieve the copied data from the DataObject and take whatever action is appropriate for the control. The following example demonstrates how to drop a String into a TextBox.
Code39 Creator In None
Using Barcode creator for Microsoft Excel Control to generate, create Code 39 Extended image in Microsoft Excel applications.
www.OnBarcode.com
Reading UPCA In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
' VB Private Sub TextBox2_DragDrop(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop TextBox2.Text = e.Data.GetData(DataFormats.Text) End Sub // C# private void textBox2_DragDrop(object sender, DragEventArgs e) { textBox2.Text = (string)e.Data.GetData(DataFormats.Text); }
Reading Barcode In .NET Framework
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Encode Bar Code In Visual Studio .NET
Using Barcode drawer for Reporting Service Control to generate, create barcode image in Reporting Service applications.
www.OnBarcode.com
Implementing Drag and Drop Between Applications
UPC - 13 Creator In Java
Using Barcode drawer for BIRT reports Control to generate, create EAN13 image in Eclipse BIRT applications.
www.OnBarcode.com
Decoding Bar Code In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Drag-and-drop operations between .NET Framework applications are intrinsically supported by the system. No additional steps need to be taken to enable drag-and drop operations that take place between applications. The only conditions that must be satisfied to enable a drag-and-drop operation between applications to succeed are:
Encode PDF417 In None
Using Barcode printer for Microsoft Word Control to generate, create PDF-417 2d barcode image in Microsoft Word applications.
www.OnBarcode.com
Encode ECC200 In .NET
Using Barcode encoder for .NET Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
www.OnBarcode.com
The target control must allow one of the drag effects specified in the DoDragDrop method call. The target control must accept data in the format that was set in the DoDragDrop method call.
Implementing Drag and Drop in a TreeView Control
A common scenario for the TreeView control is to allow the user to rearrange the struc ture of the tree at run time. This can be implemented with drag and drop. Drag and
11
Advanced Topics in Windows Forms
drop in a TreeView control is slightly different than in regular controls. When a drag operation is initiated on a TreeView node, the TreeView control raises the ItemDrag event, which passes an instance of ItemDragEventArgs to the method that handles the event. The ItemDragEventArgs object contains a reference to the TreeNode that is being dragged, and this reference can be copied to the DataObject in the DoDragDrop method. The following procedure describes how to implement drag-and-drop func tionality in a TreeView control.
To implement Drag-and-Drop functionality in a TreeView control
1. Set the AllowDrop property of the TreeView to True. This enables the DragEnter and DragDrop events to be raised from the TreeView control. 2. In the ItemDrag of the TreeView event handler, call the DoDragDrop of the TreeView method, specifying the Item property of the ItemDragEventArgs object as the Data parameter, as shown in the following example:
' VB Private Sub TreeView1_ItemDrag(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag TreeView1.DoDragDrop(e.Item, DragDropEffects.Move) End Sub // C# private void TreeView1_ItemDrag(object sender,
System.Windows.Forms.ItemDragEventArgs e)
treeView1.DoDragDrop(e.Item, DragDropEffects.Move);
3. In the DragEnter event of the TreeView event handler, set the Effect property of the DragDropEventArgs to an appropriate value, as shown in the following example:
' VB Private Sub TreeView1_DragEnter(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter e.Effect = DragDropEffects.Move End Sub // C# private void treeView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e As) {
e.Effect = DragDropEffects.Move;
4. In the DragDrop event handler, examine the data contained in the DataObject of DragDropEventArgs to determine if a TreeNode is present. If a TreeNode is present, implement code to move the TreeNode to the appropriate spot. The following
Copyright © OnBarcode.com . All rights reserved.