C#代码
- 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 WindowsApplication2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- pcbPic.DoubleClick += new EventHandler(pcbPic_DoubleClick);
- }
-
- void pcbPic_DoubleClick(object sender, EventArgs e)
- {
- OpenFileDialog ofdPic = new OpenFileDialog();
-
- ofdPic.Filter = "JPG(*.JPG;*.JPEG);gif文件(*.GIF)|*.jpg;*.jpeg;*.gif";
-
- ofdPic.FilterIndex = 1;
-
- ofdPic.RestoreDirectory = true;
-
- ofdPic.FileName = "";
- if (ofdPic.ShowDialog() == DialogResult.OK)
- {
-
- string sPicPaht = ofdPic.FileName.ToString();
-
-
- FileInfo fiPicInfo = new FileInfo(sPicPaht);
-
- long lPicLong = fiPicInfo.Length / 1024;
-
- string sPicName = fiPicInfo.Name;
-
- string sPicDirectory = fiPicInfo.Directory.ToString();
-
- string sPicDirectoryPath = fiPicInfo.DirectoryName;
-
-
-
-
-
- Bitmap bmPic = new Bitmap(sPicPaht);
-
-
- if (lPicLong > 4000)
- {
- MessageBox.Show("此文件大小為" + lPicLong + "K;已超過最大限制的400K范圍!");
- }
- else
- {
- Point ptLoction = new Point(bmPic.Size);
- if (ptLoction.X > pcbPic.Size.Width || ptLoction.Y > pcbPic.Size.Height)
- {
-
-
-
-
- pcbPic.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
-
- pcbPic.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- }
-
- pcbPic.LoadAsync(sPicPaht);
-
-
-
-
-
-
-
- }
- }
- }
-
- }
|