drag and drop on NotifyIcon in tray in C# - c#

I am trying to create a C# application that runs in tray where I can drop files on it's icon.
Is there any way to get the path of the file dropped on the System Tray icon? System.Windows.Forms.NotifyIcon does not have any events related to drag and drop.

it's not possible to do this, the easy way.
You can show a dummy Form, if the cursor is in a special area near the notifyicon.
The dummy Form can get the filepath of the droped file.

It has az example, but it's not fully and written in C++ :(
DragnDropOnTrayIcon

It actually is possible to do with a slightly hacky method. Fluffy App does this for its file uploader. It uses Spifftastic which uses a pretty neat little method to identify the location of the tray icon. Then a transparent window is placed over the location of the icon and used as the actual drop target, but to the end user it all appears to be dropping the file on the icon.

Related

Preserve notify icon autohide status when executable moves to another physical location

By default, Windows hides the notify icons in the taskbar, and user can see them by clicking on the arrow button. But user can drag those and drop them into the taskbar, so it'll be always visible. This preference will be saved for that executable.
However, my WPF app uses Squirrel.Windows for installation and update, and Squirrel.Windows creates a new executable (in a different path) for each update. So Windows will treat it as another executable, and that preference about notify icon is reset. (It hides again, even if user dragged it to taskbar in the previous version)
Is there any way I can preserve that preference of user across updates?
Maybe there's an identifier or something I can uniquely set? or any other ideas?
I'm currently using System.Windows.Forms.NotifyIcon on my WPF app. But I'm open to using alternatives if an alternative can help solving this issue.

How to create an icon that can be dragged to explorer or skype to save/send a file?

I'm working on a tool that generates output that I'd like the user to be able to conveniently send to Skype or other running applications rather than simply saving it if required.
Back when I used Acorn's RiscPC, the recommended style of the 'Save As' feature was a small dialog with an icon that represented the file, that you could drag to a folder to save, or drag to another application to send it to that app rather than saving it.
Right now, users need to save the file, then find the file in Windows Explorer and drag it to Skype from there. Sure I could easily add a 'Show in folder' icon, but it would be much neater to simply drag it straight to Skype.
Anyone know how to do this, or if it's been done before I can have a look at?
I should emphasize, I'm not specifically talking about dragging stuff to Skype, I could look at the Skype API for that, I'm talking about simulating a drag generally, as if it were a file dragged from explorer.
If you're using WinForms, here is a CodeProject article that shows you bi-directional drag and drop to and from Explorer/your application. Look here for WPF.
Hope this helps!

I want to drag an image from a Silverlight UIElement and drop it on the users Desktop or Windows Explorer

I have a Silverlight control containing an image. I want the user to be able to drag the image out of the Silverlight application and drop it anywhere they would be able to drop an image. For example, to the Desktop or to a PowerPoint slide or Word document. Everything that I have read thus far says it cannot be done but I find that hard to believe. I'm very new to Silverlight and RIA development so any help would be much appreciated.
Below is the code sample in my WinForm Form but the drag never starts.
string[] aString = { imagePath };
DataObject data = new DataObject(DataFormats.FileDrop, aString);
data.SetData(DataFormats.StringFormat, imagePath);
DoDragDrop(data, DragDropEffects.Copy);
Well the trouble is that a drag operation in Silverlight doesn't have simple access to anything outside the browser (by design). Depending on the user's settings you even have to get explicit permission for clipboard operations and sandboxed temporary file storage. This really sounds like a task better suited to a WPF application (perhaps with web deployment?) or some other desktop application technology.
However, that being said here are some things you could try/consider:
Silverlight/Javascript/ActiveX combination hosted in Internet Explorer
Silverlight 5 "Out of Brower" & P/Invoke (I heard P/Invoke will be supported when Silverlight 5 comes out)
Silverlight connecting to a web service running on the same computer (crazy, but you didn't ask for "not crazy", you asked for possible)
I am not very familiar with drag and drop in the Win32 API so it would take a lot of research and experimentation before I could confirm that this was even possible (and I can already tell you it isn't practical).
Edit: Based on the extra information you provided about the question I suspect it is possible to do what you are attempting. First, are you using WPF or WinForms? I assume WPF but one of your comments says WinForms. I wasn't very familiar with WPF drag/drop operations, but having looked into it, I think your code is on the right path. I created a WPF application and initiated a drag during a KeyDown event. This meant that the mouse button was not necessarily pressed. If I initiated the DragDrop while the button was down it worked. If I initiated while the mouse button wasn't down, I had to push the mouse button down and the drag operation would start (this was unexpected since I assumed the mouse would have to already be down). If I pressed the mouse down outside the application, then gave the WPF app focus (ALT+Tab), then initiated the DragDrop while the mouse button was still down, it didn't work. I got a reference to the MouseDevice and checked the LeftButton property, and the state was showing as "Released" even though the button was still being held down. It seems the key here is the way drag/drop interacts with internal mouse state. You might have to find a way to set the mouse state (maybe with the UI Automation API?). At this point it should be painfully obvious that this whole thing is a hack (even though it is probably possible to get it to work somehow).
The solution we came up with was as follows. The RIA i.e. Silverlight sends a message to our Desktop application WinForms with the path of the image to drag along with the bounding rectangle in screen coordinates that we want to start the drag from. The Desktop code creates and places a Panel over the area that we want to drag from. This panel is where we use DoDragDrop to initiate the native drag when the user left clicks. Since this panel is placed outside and above the silverlight control, everything works perfect. Sandbox defeated.
I have been working on some Silverlight apps for the past few months and fully investigated your exact requirements only to find it was not possible. I believe you can drag from the file system, from Silverlight control to control, but not to the file system.
Does Silverlight 4 support drag and drop from app to desktop?
http://msdn.microsoft.com/en-us/library/dd772166%28v=vs.95%29.aspx

How to create UI similar to file replace dialog in window 7 using C# Windows Forms?

I need to create a dialog that allows user to choose between several rather complex actions. I really like the usability of the windows 7 file replace dialog and I think it would suit my needs very well. Here's a screenshot for reference:
Is it possible to use the controls that were used for windows dialog? If not, how would you recommend creating UI similar to this dialog?
Seems like this could easily be done with a window containing a few labels for the text and three custom controls - with some images for the arrows and file icons - each of which changes their background image when the user mouses over them - and fires an event the window picks up on when they are clicked. Fairly standard WinForms stuff.
Is there a particular part of the process you need some extra help with? Like, for example, the mouse over?

C# Drag and drop to application taskbar icon

Is it possible to drag and drop (files, text) to the taskbar icon of a WindowsForms application (C#)?
I know there's no easy way to do it for the tray icon (it involves using Win32 API and hooks), but I was wondering if it's possible for the taskbar.
That's not possible, but the window manager automatically restores the minimized window if you hover over it long enough in the taskbar. Once restored, you can access all the drop targets your window implements.
It is possible, at least in Windows 7. Note that the blog post which the two older answers refer to is from 2004. In Windows 7 and possibly previous versions, it is possible to drop files onto applications on the taskbar if you hold shift while dropping. Examples of applications that support this are Firefox, Internet Explorer, Notepad, etc.
In order to support it, your exe needs to be able to support the command line myapp.exe <some file path> and I believe you need registry entries similar to those described in this SO answer.
Update:
I added this to one of my applications, and it works. You do not need the registry entries.
This is fundamentally impossible.

Categories

Resources