Tuesday 12 November 2013

c# load picture

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog x = new OpenFileDialog();
            x.Title = "pic selection";
            x.InitialDirectory = "c:\\";
            x.Filter = "all files (*.*)|*.*|image files(*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif";
            x.FilterIndex = 2;
            if (x.ShowDialog() == DialogResult.OK)
            { pictureBox1.Image = Image.FromFile(x.FileName); }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

No comments:

Post a Comment