這裡來寫一支SHOW圖程式,此程式在點擊BUTTON後會呼叫出一個視窗來顯示圖片。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ImageForm Myimage = new ImageForm();//建立秀圖物件
Myimage.Show();//顯示秀圖照片
}
class ImageForm : Form
{
Image image;
public ImageForm()
{
image = Image.FromFile(@"D:\MyPhoto\IMG_3841.JPG");
this.Text = @"D:\MyPhoto\IMG_3841.JP";
//載入影像的程式碼放這
}
protected override void OnPaint(PaintEventArgs e)
{
this.Height = 600;
this.Width = 800;
//顯示出影像的程式碼在這
e.Graphics.DrawImage(image, 0, 0, Width, Height);
}
}
}
}