using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Reflection;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string strFilename = "";
OpenFileDialog dlgOpen = null;
try
{
dlgOpen = new OpenFileDialog();
dlgOpen.Filter = "All Image Files(*.*)|*.*";
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
if (dlgOpen.FileName == "") return;
strFilename = dlgOpen.FileName;
pictureBox1.Image = Image.FromFile(strFilename);
this.SetImageSizeMode(pictureBox1);
}
}
catch (Exception ex)
{
MessageBox.Show("无法识别的图片格式(" + strFilename + ")\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (dlgOpen != null)
dlgOpen.Dispose();
dlgOpen = null;
}
}
/********************************************************************************************************/
private void SetImageSizeMode(PictureBox pImage)
{
if (pImage == null) return;
Image imgRe
c# 图片截图
最新推荐文章于 2025-06-03 13:37:15 发布