简体   繁体   中英

Drag text over C# application icon to launch app

I have a C#, Windows 7, forms application that works with the clipboard to retrieve text and then process it accordingly. I'd like to modify the app to allow a user to highlight text from any source (word, e-mail, etc.) and drag that text over my applications icon to launch the program.

I can get command line arguments to work like this:

static void Main(string[] args)
  {
    if (args != null)
    {
      for (int i = 0; i < args.Length; i++){
         varItemNumber = args[i];
      }
    }//...

But the application wont launch on the desktop when text is dropped on it.

Found similar question which is related to console applications.

Is there a way to enable objects to be dropped onto the application icon?

According to this question , what you're doing ought to work. SOme people recommend this attribute over the Main function:

 [STAThread]

But other people have complained that UAC issues have prevented them doing this. So that (UAC) might be part of the issue.

Another thought: might you get different results for a shortcut vs. actually having the application installed to the desktop?

Finally: according to this , what you need is a Shell Drop Handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM