首页 > Windows开发 > 详细

WPF 学习笔记(十二)

时间:2018-09-04 00:37:48      阅读:180      评论:0      收藏:0      [点我收藏+]

(一)打开、保存对话框

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void openBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "文本文件|*.txt|视频文件|*.avi";
            if (ofd.ShowDialog() == true)
            {
                string fileName = ofd.FileName;
                MessageBox.Show(fileName);
            }
            else
            {
                MessageBox.Show("打开失败");
            }
        }

        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "文本文件|*.txt|视频文件|*.avi";
            if (sfd.ShowDialog() == true)
            {
                string fileName = sfd.FileName;
                MessageBox.Show(fileName);
            }
            else
            {
                MessageBox.Show("保存失败");
            }
        }

 (二)打开图片案例

使用到控件Image

        private void openBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPG|*.jpg|png|*.png";
            if (ofd.ShowDialog() == true)
            {
                string fileName = ofd.FileName;
                image.Source = new BitmapImage(new Uri(fileName));
               
            }
            else
            {
                MessageBox.Show("打开失败");
            }
        }

 

WPF 学习笔记(十二)

原文:https://www.cnblogs.com/dLong/p/9581812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!