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());
            }
        }
    }
     
  • 相关阅读:
    MOS
    1- Bluetooth开发
    1- Bluetooth
    MCU 51-10 Infrared Communication
    1- STM32 HAL库学习 GPIO配置点亮LED灯
    MCU 51-9 DS18B20 Temperature Sensor
    MCU 51-8 AD/DA
    C语言讲义——变量(variable)
    C语言讲义——注释
    C语言讲义——“编译、链接”
  • 原文地址:https://www.cnblogs.com/code1992/p/2860378.html
Copyright © 2011-2022 走看看