分享

C#利用Picturebox控件显示图片

 goodwangLib 2018-01-30
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;namespace showPicture{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private string pathname = string.Empty;     //定义路径名变量        private void button1_Click(object sender, EventArgs e)   //打开方法        {            OpenFileDialog file = new OpenFileDialog();            file.InitialDirectory = '.';            file.Filter = '所有文件(*.*)|*.*';            file.ShowDialog();            if (file.FileName != string.Empty)            {                try                {                    pathname = file.FileName;   //获得文件的绝对路径                    this.pictureBox1.Load(pathname);                }                catch (Exception ex)                {                    MessageBox.Show(ex.Message);                }            }          }        private void button2_Click(object sender, EventArgs e)  //保存方法        {  SaveFileDialog save = new SaveFileDialog();            save.ShowDialog();            if (save.FileName != string.Empty)            {                pictureBox1.Image.Save(save.FileName);            }          }    }}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多