码迷,mamicode.com
首页 > 其他好文 > 详细

D23_02_窗口交互 OpenFileDialog MessageBox

时间:2014-11-02 13:49:51      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   for   sp   

bubuko.com,布布扣

 

 

<Window x:Class="demo.OpenFileTest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="OpenFileTest" Height="300" Width="300">
    <DockPanel Margin="5">
        <Button DockPanel.Dock="Top" Click="cmdOpen_Click" >open</Button>
        <ListBox Name="lstFiles"></ListBox>
    </DockPanel>
</Window>

 

OpenFileTest(窗体类)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace demo
{
    /// <summary>
    /// OpenFileTest.xaml 的交互逻辑
    /// </summary>
    public partial class OpenFileTest : Window
    {
        public OpenFileTest()
        {
            InitializeComponent();
        }

        private void cmdOpen_Click(object sender,RoutedEventArgs e)
        {
            OpenFileDialog myDialog = new OpenFileDialog();
            myDialog.Filter = "Image Files(*.BMP;*.JPG;*.Gif)|*.BMP;*.JPG;*.Gif" + "|All Files(*.*)|*.*";
            //检查文件是否存在
            myDialog.CheckFileExists = true;
            //设置文件可以多选
            myDialog.Multiselect = true;

            if (myDialog.ShowDialog() == true)
            {
                lstFiles.Items.Clear();
                foreach (string file in myDialog.FileNames)
                {
                    //lstFiles为ListBox的名称
                    lstFiles.Items.Add(file);
                }
            }
        }
    }
}

 

MessageBox.Show("提示内容", "提示标题", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

D23_02_窗口交互 OpenFileDialog MessageBox

标签:style   blog   http   io   color   ar   os   for   sp   

原文地址:http://www.cnblogs.com/xiepengtest/p/4069025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!