Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement drag and drop in VB.NET

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to achieve drag-and-drop VB.NET, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

VB.NET is still quite commonly used, so I studied the implementation of drag-and-drop VB.NET, here to share with you, I hope to be useful to you. Windows users are generally divided into two categories: one is accustomed to operating with the keyboard and the other is used to operating with the mouse. Programmers usually provide shortcuts (underlining commands or letters) or shortcuts (using a combination of CTRL and letters) to take care of those who are used to the keyboard, but those mouse users are ignored. Because programmers are generally used to using keyboards, their emphasis on keyboard operation is understandable, but every programmer should also consider providing mouse support.

One of the things that mouse users expect is to be able to VB.NET drag and drop in the application. If you notice some large applications or windows itself, drag-and-drop operations can be seen almost everywhere. For example, users may be used to operations such as dragging and dropping files in windows Explorer, or dragging and dropping text in word.

Although drag-and-drop operations are ubiquitous, only a handful of programmers implement drag-and-drop functionality in the programs they write, most likely because they think that VB.NET implementation of drag-and-drop may be harder than expected. This article lists examples of how to move text, pictures, or files between windows, forms, and even applications, and shows how easy it is to drag and drop in VB.NET.

How to drag and drop

Drag and drop is actually like copying and pasting with a mouse, so you must have a source that can be copied or moved, and a destination that can be pasted. During these two operations, the data is stored in memory. Copy and paste uses a cut version, while drag and drop uses a Dataobject object that is essentially a private clipboard.

The following is a time series of typical drop operations:

1. Dragging is initialized by calling the DoDragDrop method of the source control. DoDragDrop has two parameters.

◆ data, which specifies the data to be transferred

◆ allowedEffects, which specifies what operations are allowed (copy or move)

This automatically creates a new Dataobject object

2. Then the GiveFeedBack event is triggered in turn. In most cases, you don't need to worry about GiveFeedBack events, but if you want to customize the mouse pointer during drag and drop, you can add your code in these places.

3. Any control that has an AllowDrop property and is set to True is an implied Drop object. The AllowDrop property can be set in the properties window at design time or automatically loaded in the Form_load event.

4. When the mouse moves over a control, the DragEnter event of the control is fired at the same time. The GetDataPresent method is used to confirm whether the dragged data is appropriate for the target control, and the Effect property is used to display the appropriate mouse pointer.

5. If the user releases the mouse over a valid target control, the DragDrop event is also fired. The code in the DragDrop event handle releases the data from the DataObject object and displays it in the target control.

The above is how to implement drag and drop in VB.NET. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report