|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drag Drop Data pictures to my FormHello 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) 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); } -- Show quoteHide quoteBob 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. <ravising***@gmail.com> wrote in message news:1104784983.292277.154190@f14g2000cwb.googlegroups.com... > 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) > 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 "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> a écrit dans le message de news: Ogt26rd8EHA.2***@TK2MSFTNGP15.phx.gbl...Show quoteHide quote > 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); > > } > > -- > 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. > > > > > > <ravising***@gmail.com> wrote in message > news:1104784983.292277.154190@f14g2000cwb.googlegroups.com... >> 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) >> > > 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
Adding/Updating assemblies in GAC during runtime and not during Se
OT: Replacement for Adobe Acrobat Label with Transparent Background Inheritance in forms which inherit template forms Problem with FileSystemWatcher/Tray Notifier App MessageBox and Focus New Thread MessageBox and Form load Outlook Style Calendar Control Programming with Dual Monitors |
|||||||||||||||||||||||