双击打开文件 [英] open a file by double click

查看:84
本文介绍了双击打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个图像查看器Windows应用程序。我希望当我双击一个图像文件然后它应该用我的应用程序打开。

I am creating a image viewer windows application.I want that when i double click on a image file then it should be open with my application.

推荐答案

请看到问题的评论:你需要设置文件关联。如果您需要以编程方式执行此操作,请参阅此CodeProject文章:系统文件关联 [ ^ ]。



参见:

http://mel-green.com/2009/04/c-set-file-type-association/ [ ^ ],

http://www.java2s.com/Code/CSharp/Development-Class/RegistryFileAssociation.htm [ ^ ]。



-SA
Please see the comments to the question: you need to set file associations. If you need to do it programmatically, please see, for example, this CodeProject article: System File Association[^].

See also:
http://mel-green.com/2009/04/c-set-file-type-association/[^],
http://www.java2s.com/Code/CSharp/Development-Class/RegistryFileAssociation.htm[^].

—SA


非常简单的方法

在部署设置时将ur关联类型添加到文件类型编辑器中
Very easy method
Add ur associations type into File type editor while deploying set up


如果要在DataGrid中显示数据并编写视图代码,可以引发DoubleClick事件里面



You can raise the DoubleClick event if you are displaying the data in DataGrid and write the view code inside

//write connection to server
try
{
    if (dataGridView1.RowCount > 0)
    {
        DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
        document_type = row.Cells[7].Value.ToString();
        tag11 = row.Cells[1].Value.ToString();
        tag22 = row.Cells[2].Value.ToString();
        tag33 = row.Cells[3].Value.ToString();
        tag44 = row.Cells[4].Value.ToString();
        date1 = row.Cells[8].Value.ToString();

    }

    if (dataGridView2.RowCount > 0)
    {
        DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
        document_type = row.Cells[7].Value.ToString();
    }

    if (
        document_type == "Image"
        || document_type == "Pdf Document"
        || document_type == "Audio"
        || document_type == "Video"
        || document_type == "Text"
    )
    {
        DocumentView view = new DocumentView(documentname);
        view.ShowDialog();
        view_count();
    }
    else
    {
        int lng = Application.ExecutablePath.Length; ;
        int lng2 = lng - 18;
        string pth = Application.ExecutablePath.Substring(0, lng2);
        string destinationfolder = pth + "Documents";
        string save_path1 = destinationfolder + @"\" + documentname;
        System.Diagnostics.Process.Start(save_path1);
    }
}
catch (Exception e3)
{
    int lng = Application.ExecutablePath.Length; ;
    int lng2 = lng - 18;
    string pth = Application.ExecutablePath.Substring(0, lng2);
    string destinationfolder = pth + "Documents";
    string save_path1 = destinationfolder + @"\" + documentname;
    MessageBox.Show("System Or Windows can not open the Selected Document");
    System.IO.StreamReader sr = new
    System.IO.StreamReader(save_path1);
    MessageBox.Show(sr.ReadToEnd());
    sr.Close();
}


这篇关于双击打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆