Monday, July 26, 2010

C # drag and drop source Xiangjie 1



The operating practices, we can Windows applications users are divided into two categories, first is preferred to use the keyboard of the user, the second is the preference of the user using the mouse. Experience for many programmers to fully understand, be sure to provide hot key (underscore will show the rapid character key) and the shortcut key (for example: Ctrl + key combination of a character) to a large number of users using the keyboard, but but often ignore the mouse users. As the programmers themselves tend to keyboard users, so special emphasis on the function-oriented keyboard is understandable, but every programmer should also take into account the full support of the mouse is.

In fact, most users expect the mouse is on the full support of drag and drop. However, closer inspection the majority of Windows applications or Windows operating system itself, we find that drag and drop capability is everywhere. For example, the user is already accustomed to Windows Explorer, drag and placement of files and drag in Microsoft Word and text placed.

Unfortunately, only a very small number of Visual C # programmers will develop their applications with complete drag and drop function, of course, one of the reasons causing this phenomenon is to achieve drag and drop functionality does have its difficulty and complexity. This section will let you know to use Visual C # 2003 ~ 2005 version after the release function of real drag is how a simple thing. We will show how the actual window inside the body, between the form and move between the application and copy text, pictures and documents.

Drag and drop operation is how it works

Drag and drop actually cut and paste (or copy and paste) is no different, but it is to use the mouse instead of using the keyboard. In both operations, you will have a source (that is, you cut or copied object) and a target (that is, between you paste). No matter what kind of operation, during operation, the data will exist in memory a copy. Cut and paste will be used to the clipboard, and drag and drop to a DataObject object will be used, in fact, DataObject object is like a private clipboard.

In a typical drag and drop operation will cause the following event sequence:

1. You can call the source control DoDragDrop method to initialize the drag operation. DoDragDrop method syntax is as follows:

DragDropEffects DoDragDrop (

Object data,

DragDropEffects allowedEffects) DoDragDrop method will accept the following two parameters:

A new DataObject object will automatically be created.

2. Then lead to the source control GiveFeedback event. In most cases, you do not need to deal with GiveFeedback event, but if you want to display a custom during drag the mouse pointer, you can write GiveFeedback event handler code to complete the set.

3.AllowDrop property is set to True, any controls can be placed target. You can design the "Properties" window as the target control to AllowDrop property set to True, or is in the operational phase in the form Load event handler as the target control will be set to AllowDrop property True.

4. When you move the mouse pointer over any control, it will lead to the control of the DragEnter event. We usually target the control of the DragEnter event handler, use the GetDataPresent method to detect whether the drag data format for the target control, and use the DragEventArgs type parameters allowed to set the Effect property of the placement operation.

5. If the user placed in a valid target release the mouse button, it will lead to target control DragDrop event. We usually target the control of the DragDrop event handler write the code, retrieve data from a DataObject object and displays the target control.

About drag and drop operation, you must note the following:

Some controls have custom drag-specific events. For example, ListView and TreeView control to have ItemDrag event. When a drag operation is being executed, you can handle QueryContinueDrag event, which will be the system "requires the use of permission" to continue to drag operation. When the time of that approach, but also a call to those who drag operation on the impact of the method is the right time. For example, when the mouse pointer over the top of the TreeView control when the start of a TreeNode. You can also define your own DataFormats. Approach is very simple, you need to specify your object SetData method of the Object parameter, specify the same time make sure the object is serializable. In addition, you can also use KeyState property in order to drag and drop operation according to the keys pressed during to produce specific results. For example, when Ctrl key is pressed, usually by dragging the data replication. Drag text

Drag operation is the simplest realization of a TextBox control to a certain move or copy text to another TextBox control. Of course, you can also use the copy or cut and paste operations between the two TextBox controls to copy or move data, but use the drag and drop to the completion of such action will definitely be more efficient.







Recommended links:



Fans paradise - watch the GAME with three arms PPMate



Education



Easy Security And Privacy:



UIM PHS MARKET price of 700 yuan more than today



Charles Zhang: Sohu Is Looking For The Next Opponent



LIU Xu Micro point: there will be more soon to be opened Insider



A little more effort, it will become good by a qualified



Ninth Zhongguancun Computer Festival was officially opened



what is mkv format



Flv to avi converter



converting flac to MP3



PIMS And Calendars reviews



rmvb



No comments:

Post a Comment