zoukankan      html  css  js  c++  java
  • C# 文件关联 (jpg等图片格式为例)

     
    View Code
    //使用方法:右键要打开的图片文件,打开方式-选择默认程序-浏览- pic.exe
    
    //Form1.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    using System.IO;
    
    namespace pic
    {
        public partial class Form1 : Form
        {
            private static string openfilepath = "";
    
            public Form1()
            {
                InitializeComponent();
            }
    
            public Form1(String[] args)
            {
                InitializeComponent();
                //打开前会显示文件的路径
                MessageBox.Show(args[0]);
                try
                {
                    openfilepath = args[0];
                    Image img = Image.FromFile(openfilepath);
                    pictureBox1.Image = img;
                }
                catch
                {
                    MessageBox.Show("打开文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }           
            }
        }
    }
    
    
    //Program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace pic
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main(String[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);          
    
                if (args.Length > 0)
                    Application.Run(new Form1(args));
                else
                    Application.Run(new Form1());
            }
        }
    }
     
  • 相关阅读:
    python库--pandas--Series.str--字符串处理
    前端--jstree--异步加载数据
    python库--flask--创建嵌套蓝图
    Git--生成公钥和私钥并添加gitlab访问权限
    es查询--请求body
    python生成时间序列(date_range)
    golang使用组合完成伪继承
    golang interface类型的动态绑定
    ruby环境安装草稿
    openfire
  • 原文地址:https://www.cnblogs.com/code1992/p/2860378.html
Copyright © 2011-2022 走看看