积极答复者
如何拖动文件到图标上然后打开运行

问题
答案
-
捕捉drag&drop事件, Process类可以用来启动一个新的进程, 你可以把拖拽文件的路径作为参数传给即将要启动的进程.
Eric Yang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年6月8日 1:13
-
你好
如果我没理解错的话,你是想拖动一个txt文件到一个exe上面,然后把txt里面的文本显示在程序里面的textbox里面。
下面的代码可以实现你的需求。
cs文件:
public partial class Form1 : Form { public Form1(string[] args) { InitializeComponent(); InitCustomComponents(args); } private void InitCustomComponents(string[] args) { if (args != null && args.Length == 1) { string file = args[0]; try { textBox1.Text= File.ReadAllText(file); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
Program.cs
希望对你有帮助。static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(args)); } }
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年6月8日 1:13
全部回复
-
捕捉drag&drop事件, Process类可以用来启动一个新的进程, 你可以把拖拽文件的路径作为参数传给即将要启动的进程.
Eric Yang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年6月8日 1:13
-
你好
如果我没理解错的话,你是想拖动一个txt文件到一个exe上面,然后把txt里面的文本显示在程序里面的textbox里面。
下面的代码可以实现你的需求。
cs文件:
public partial class Form1 : Form { public Form1(string[] args) { InitializeComponent(); InitCustomComponents(args); } private void InitCustomComponents(string[] args) { if (args != null && args.Length == 1) { string file = args[0]; try { textBox1.Text= File.ReadAllText(file); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
Program.cs
希望对你有帮助。static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(args)); } }
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年6月8日 1:13