问题描述
我在dot net Compact框架中开发移动应用程序。我设法编辑注册表HKEY_CLASSES_ROOT,以便点击具有.xyz扩展名的文件将打开我的应用程序。基本上,我需要在点击它时对该文件进行一些操作。
Hi, Im developing a mobile application in dot net Compact framework. I managed to edit the registry HKEY_CLASSES_ROOT so that a click on file with .xyz extension will open my application. basically, i need to do some operation on this file when it's clicked.
但是,我意识到如果我第一次这样做,它会在 static void Main
。但是当程序运行时我再次单击带有.xyz扩展名的文件时,它不会加载程序 static void Main
。我尝试在当前正在运行的表单中设置断点,但仍然没有。
however, i realise that if i do that the first time, it reaches program.cs at static void Main
. but when the program is running and i click on the file with .xyz extension again, it doesnt loads the programstatic void Main
. i tried setting breakpoints at the form that is currently running but still nothing.
那么它去哪里了?如何检测文件.xyz被单击并执行某些操作?
so where does it go to? how can i detect file .xyz is clicked and do something??
推荐答案
[MTAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}
注意Main方法的签名。
解释如果你没有:
args参数将包含用户想要打开的文件名(包括路径),就像用参数执行你的应用程序一样。因此,如果用户单击文件"\storage card \ folder1 \ file.xyz",您的应用程序将以
" MyApplication.exe \storage card \ folder1 \ file.xyz"执行。你可以通过访问args数组的元素0来获取文件名
notice the signature of the Main method.explaination in case you didn't:the args parameter will contain the file name that the user want's to open (including the path), it's like executing your application with parameters. so if the user clicks the file "\storage card\folder1\file.xyz" your application will be executed as"MyApplication.exe \storage card\folder1\file.xyz" and you can get the file name by accessing the element 0 of the args array
string FileName = args[0];
确保在尝试查询之前检查参数可用性。使用args.getUpperBound()。
make sure you check for the parameter availablility before you try to query it. use args.getUpperBound().
希望这会有所帮助。
这篇关于C#CF:如何使用我的程序打开特定的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!