您的位置:首页 > 编程语言 > C#

C# 调用画图工具打开图片

2011-09-25 12:57 323 查看
using System;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Text.RegularExpressions;

using System.Windows.Forms;

using System.Diagnostics;
namespace WinFormBrowserImage

{

    public partial class FormImage : Form

    {

        #region

        private DataTable table;

        private PictureBox picture;

        private Splitter split;

        private OpenFileDialog openFile;

        #endregion

        public FormImage()

        {

            #region

            InitializeComponent();

            openFile = new OpenFileDialog();

            openFile.Filter = "图像格式(*.BMP;*.GIF;*.JPG;*.PNG)|*.bmp;*.gif;*.jpg;*.png";

            this.AllowDrop = true;

            this.HelpButton = true;

            this.MaximizeBox = false;

            this.MinimizeBox = false;

            this.BackgroundImageLayout = ImageLayout.Zoom;

            this.StartPosition = FormStartPosition.WindowsDefaultBounds;

            this.Text = "单击标题栏里的帮助按钮可加载图片";

            #endregion

        }

        protected override void OnDragEnter(DragEventArgs e)

        {

            base.OnDragEnter(e);

            this.Activate();

            DataObject data = e.Data as DataObject;

            if (data.ContainsFileDropList())

            {

                FileInfo info = new FileInfo(data.GetFileDropList()[0]);

                if (Regex.IsMatch(info.Extension, @".(bmp|gif|jpg|png)", RegexOptions.IgnoreCase)) // 指定不区分大小写的匹配。

                {

                    this.Text = info.Name;

                    this.BackgroundImage = Image.FromFile(info.FullName);

                    Environment.CurrentDirectory = info.DirectoryName;

                    openFile.FileName = info.FullName;

                }

            }

        }

        protected override void OnHelpButtonClicked(CancelEventArgs e)

        {

            base.OnHelpButtonClicked(e);

            e.Cancel = true;

            if (openFile.ShowDialog(this) == DialogResult.OK)

            {

                this.Text = openFile.SafeFileName;

                this.BackgroundImage = Image.FromFile(openFile.FileName);

            }

        }

        protected override void OnDoubleClick(EventArgs e)

        {

            base.OnDoubleClick(e);

            if (File.Exists(this.Text))

            {

                Process.Start("mspaint.exe", this.Text);

                //using (Process psi = new Process())

                //{

                //    ProcessStartInfo info = psi.StartInfo;

                //    info.FileName = "mspaint.exe"; // 画图工具。

                //    info.Arguments = this.Text;

                //    info.WorkingDirectory = Environment.CurrentDirectory; // 当前工作目录。

                //    info.WindowStyle = ProcessWindowStyle.Maximized; // 窗口最大化。

                //    psi.Start();

                //}

            }

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  工具 c# table class 工作