Drag and Drop like Windows Explorer

  • Thread starter Thread starter Clyde
  • Start date Start date
C

Clyde

I am trying to implement the user feedback provided by
Windows Explorer when draggng a filename from one place to
another.
I have the drag and drop action worked out but have had no
luck in finding how to capture the piece of the screen
into a bitmap to simulate the movement. I know this could
be done with the Windows API but can't find any way to do
it with .Net functions.

Any help is appreciated.

Clyde
 
Clyde, what do you mean by 'capture the piece of screen'? It might be
easiest if you could outline how you would do this with the Win API. From
there we can tell you whether you should use P/Invoke or if there are
managed classes to accomplish your task.
 
My terminology may be wrong. When you start to drag a
file in Explorer, the cursor changed and a muted image of
the selected file is dragged with the mouse. Some
controls, like CTreeGrid have a function,CreateDragImage
which returns the image to use. This is what I want to
implement for the DataGrid in .Net.

Clyde
 
Hi Clyde,

I think you should refer to the DataGrid's DragEnter, DragDrop, DragOver
event which are inherited from Control's DragEnter, DragDrop, DragOver
event.
You can change the cursor display by changing the DragEventArgs with
DragDropEffects enumerate.
You also can use e.Data.GetDataPresent method to determine the source
data's format.
You can find many small samples of these events in MSDN.

For your datagrid dragdrop, if you want to add this source data into the
datagrid, I think you should add this source data into the dataset, then
the datagrid will reflect the change. Then if you want to update the
database, you should use SqlDataAdapter's Update method.

If you still have anyting unclear, please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: <[email protected]>
| Sender: <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Drag and Drop like Windows Explorer
| Date: Wed, 29 Oct 2003 15:09:30 -0800
| Lines: 46
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOecbVE+iYSE3CsRVCgGO60YFwwLw==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:195225
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| My terminology may be wrong. When you start to drag a
| file in Explorer, the cursor changed and a muted image of
| the selected file is dragged with the mouse. Some
| controls, like CTreeGrid have a function,CreateDragImage
| which returns the image to use. This is what I want to
| implement for the DataGrid in .Net.
|
| Clyde
|
| >-----Original Message-----
| >Clyde, what do you mean by 'capture the piece of
| screen'? It might be
| >easiest if you could outline how you would do this with
| the Win API. From
| >there we can tell you whether you should use P/Invoke or
| if there are
| >managed classes to accomplish your task.
| >
| >--
| >Greg Ewing [MVP]
| >http://www.citidc.com/
| >
| >
| >| >> I am trying to implement the user feedback provided by
| >> Windows Explorer when draggng a filename from one place
| to
| >> another.
| >> I have the drag and drop action worked out but have had
| no
| >> luck in finding how to capture the piece of the screen
| >> into a bitmap to simulate the movement. I know this
| could
| >> be done with the Windows API but can't find any way to
| do
| >> it with .Net functions.
| >>
| >> Any help is appreciated.
| >>
| >> Clyde
| >>
| >
| >
| >.
| >
|
 
I don't have a problem with the drag and drop action. I
am using the DataGrid DragDrop, DragEnter, and DragOver
events.
When I start a drag, the cursor converts to an arrow with
two small boxes along the tail of the arrow. I know I can
change the cursor. What I would like to do is add the
small bitmap along with the cursor like Windows Explorer
does when you start to drag a file.

I don't know if the Explorer effect is a cursor only or a
cursor plus bitmap. If it is a cursor only, can you
provide some help in creating cursors on-the-fly of
arbitrary size? If it is a bitmap, how is the bitmap
generated on-the-fly?
 
Hi Clyde,

Thanks for you feedback.
I think I understand your meaning. I have done a lot research for you.
First you should be clear that the dragdrop effect should be handled by the
possible drop target container, but not the drag source.
When the drag entered your application area, you should determine the drag
source's data through the clipboard. However, you should only determine if
the clipboard contains you wanted data format.
Generally, the windows will not place all the data of drag source into the
clipboard, while it only places some certain information into the
clipboard(For example, only the filename, the file content's stream
pointer). So I think you should use the file information to retreive the
file icon, then you must draw the file icon with the mouse cursor. This all
can be done in the DragEnter and DragOver event.
But I think these steps are very complex, I recommand you do not do this.
As you can see, the Microsoft Outlook, MSN, and other applications all did
not implement this effect(file icon with curso). The windows explorer and
Internet Explorer implement this effect, because they have more information
than other applications.
So I really recommand you not implement this effect.

Hope this helps,

Best regards.
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Clyde LeFevre" <[email protected]>
| Sender: "Clyde LeFevre" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Drag and Drop like Windows Explorer
| Date: Thu, 30 Oct 2003 09:45:45 -0800
| Lines: 49
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOfDaVB98soo0s9QLetkj/am2zrBg==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:195469
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I don't have a problem with the drag and drop action. I
| am using the DataGrid DragDrop, DragEnter, and DragOver
| events.
| When I start a drag, the cursor converts to an arrow with
| two small boxes along the tail of the arrow. I know I can
| change the cursor. What I would like to do is add the
| small bitmap along with the cursor like Windows Explorer
| does when you start to drag a file.
|
| I don't know if the Explorer effect is a cursor only or a
| cursor plus bitmap. If it is a cursor only, can you
| provide some help in creating cursors on-the-fly of
| arbitrary size? If it is a bitmap, how is the bitmap
| generated on-the-fly?
| >-----Original Message-----
| >
| >Hi Clyde,
| >
| >I think you should refer to the DataGrid's DragEnter,
| DragDrop, DragOver
| >event which are inherited from Control's DragEnter,
| DragDrop, DragOver
| >event.
| >You can change the cursor display by changing the
| DragEventArgs with
| >DragDropEffects enumerate.
| >You also can use e.Data.GetDataPresent method to
| determine the source
| >data's format.
| >You can find many small samples of these events in MSDN.
| >
| >For your datagrid dragdrop, if you want to add this
| source data into the
| >datagrid, I think you should add this source data into
| the dataset, then
| >the datagrid will reflect the change. Then if you want to
| update the
| >database, you should use SqlDataAdapter's Update method.
| >
| >If you still have anyting unclear, please feel free to
| let me know.
| >
| >Best regards,
| >Jeffrey Tan
| >Microsoft Online Partner Support
| >Get Secure! - www.microsoft.com/security
| >This posting is provided "as is" with no warranties and
| confers no rights.
| >
|
 
Back
Top