Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

Drag Drop Data pictures to my Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ravisingh11@gmail.com - 03 Jan 2005 20:43 GMT
Hello all

I have a C# application, with two pictureBox 's I can successfully load
an image in one of the box drag and drop to the other box.

I want to expand this concept so I can drag and drop images from
folders, and other applications. I think I have to use .NET remoting
for this. Any ideas, pointers as to how to do this, would be greatly
appreciated.

Thanks

Ravi Singh
(UCSD)
Bob Powell [MVP] - 03 Jan 2005 21:26 GMT
You don't need remoting. You need to handle the DragEnter and DragDrop event
from the control and decide whether the clipboard contains a format of data
you can handle.

In DragEnter, check the clipboard data for formats such as bitmaps or paths
to image files. if the test is positive then allow the drop. When the drop
happens use the data in whatever way your application needs.

For example, this code enables file dropping...

protected override void OnDragEnter(DragEventArgs e)

{

if (e.Data.GetDataPresent(DataFormats.Text))

{

string path =(string) e.Data.GetData("Text");

if(File.Exists(path))

{

e.Effect = DragDropEffects.Copy;

}

else

{

e.Effect=DragDropEffects.None;

}

}

else

{

e.Effect = DragDropEffects.None;

}

base.OnDragEnter(e);

}

This should get you started on thedrop.

 protected override void OnDragDrop(DragEventArgs e)
 {

  if(e.Data.GetDataPresent("Text"))
  {
   string path=(string)e.Data.GetData("Text");
   //load an image from a file??
  }
  Invalidate();

  base.OnDragDrop(e);

 }

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> Hello all
>
[quoted text clipped - 10 lines]
> Ravi Singh
> (UCSD)
Pascal Cloup - 04 Jan 2005 18:49 GMT
Hello,

i have just tried it and this works,  but only if the i put the code in the
event handlerss of the form. The Event handlers of the Control (a PictureBox
in my case) are never called when draging a file from the desktop.

Is this a normal behaviour?

thanks,
Pascal

> You don't need remoting. You need to handle the DragEnter and DragDrop
> event from the control and decide whether the clipboard contains a format
[quoted text clipped - 76 lines]
>> Ravi Singh
>> (UCSD)
Ravi Singh (UCSD) - 05 Jan 2005 02:52 GMT
Hello Bob

Thanks for replying, as I mentioned in my original post I have the
ability to drag drop pictures within the application. But I wanted to
expand the concept so as to be able to drag drop pictures from
different folders. As Pascal mentioned and I am sure you are aware the
ability of the Drag/Drop event handlers work within the form itself.

So, how do I do this I have been looking into doing it via
IMessageFilter, but little sucess as of now. Anyone have any ideas on
how to do this in C++.

Thanks
Ravi Singh

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.