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();
//}
}
}
}
}
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#调用电脑的默认图片浏览器软件打开图片
- C#调用Windows图片和传真查看器打开图片
- 【转】C#调用Windows图片和传真查看器打开图片
- 通过Process.Start调用window自带画图工具打开文件报错无法打开Program.png
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- C#调用Windows图片和传真查看器打开图片
- C#调用Windows图片和传真查看器打开图片
- c# 中释放打开图片和 子窗体调用父窗体函数
- C#中调用系统API打开和关闭光驱
- Android 调用相机、打开相册、裁剪图片
- opencv cmd方式调用程序打开图片
- 游戏开发工具之纹理打包器-2.打开文件夹遍历指定格式的图片,以及显示到tree控件上
- C#调用默认浏览器打开网页的几种方法
- Qt调用OpenCV打开图片
- C#中使用GDI画图工具动态显示
- C#调用打印机,打印图片
- UWSC自动打开画图程序批量转换图片格式
- java调用c#wcf心得,主要解决传递图片问题
- c#调用Aspose.Word组件操作word 插入文字/图片/表格 书签替换套打
- Win8.1系统中使用画图工具调整图片大小的方法图文详解