zoukankan      html  css  js  c++  java
  • WPF 学习笔记(十二)

    (一)打开、保存对话框

    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("打开失败");
                }
            }
  • 相关阅读:
    everything is nothing
    基础算法
    OC 优化目录
    iOS 更改启动视图
    单例--iOS
    OC-Objection 学习笔记之一:简单的开始
    iOS 类库列表
    IOS 上线问题
    OC强弱引用的使用规则
    设置桌面图标
  • 原文地址:https://www.cnblogs.com/dLong/p/9581812.html
Copyright © 2011-2022 走看看