資源簡(jiǎn)介
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
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.Navigation;
using System.Windows.Shapes;
namespace ImageExplorer
{
/// <summary>
/// MainWindow.xaml 的交互邏輯
/// </summary>
public partial class MainWindow : Window
{
private BitmapImage bmi;
private string path;
public MainWindow()
{
InitializeComponent();
path = Environment.CurrentDirectory @"\image\";
GetImage();
}
private void GetImage()
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
lstImage.Items.Add(file);
}
}
private void lstImage_Drop(object sender, DragEventArgs e)
{
//僅支持文件的拖放
if (!e.Data.GetDataPresent(DataFormats.FileDrop))
{
return;
}
//獲取拖拽的文件
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
//這里需要注意,由于程序既支持拖過來(lái)也支持拖過去,那么ListBox就也能接收自身拖拽過來(lái)的文件
//為了防止鼠標(biāo)點(diǎn)擊和拖拽的沖突,需要屏蔽從程序自身拖拽過來(lái)的文件
//這里判斷文件是否從程序外部拖拽進(jìn)來(lái),也就是判斷圖片是否在工作目錄下
if (files.Length > 0 && !files[0].StartsWith(path) &&
(e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy)
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
foreach (string file in files)
{
try
{
//如果是從外部拖拽進(jìn)來(lái)的圖像,則復(fù)制該文件到工作目錄下做備份
string destFile = path System.IO.Path.GetFileName(file);
switch (e.Effects)
{
case DragDropEffects.Copy:
File.Copy(file, destFile, false);
bmi = new BitmapImage(new Uri(destFile));
imgShow.Source = bmi;
lstImage.Items.Add(destFile);
break;
default:
break;
}
}
catch
{
MessageBox.Show("已存在此文件或?qū)肓朔菆D像文件!");
}
}
}
private void lstImage_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.RightButton == MouseButtonState.Released)
{
bmi = new BitmapImage(new Uri(lstImage.SelectedItem.ToString()));
imgShow.Source = bmi;
}
}
private void lstImage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (lstImage.SelectedIndex > -1)
{
//只使用了Listbox單選功能
string[] files = new string[1];
files[0] = lstImage.SelectedItem.ToString();
DragDrop.DoDragDrop(lstImage, new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy | DragDropEffects.Move /* | DragDropEffects.Link */);
}
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
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.Navigation;
using System.Windows.Shapes;
namespace ImageExplorer
{
/// <summary>
/// MainWindow.xaml 的交互邏輯
/// </summary>
public partial class MainWindow : Window
{
private BitmapImage bmi;
private string path;
public MainWindow()
{
InitializeComponent();
path = Environment.CurrentDirectory @"\image\";
GetImage();
}
private void GetImage()
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
lstImage.Items.Add(file);
}
}
private void lstImage_Drop(object sender, DragEventArgs e)
{
//僅支持文件的拖放
if (!e.Data.GetDataPresent(DataFormats.FileDrop))
{
return;
}
//獲取拖拽的文件
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
//這里需要注意,由于程序既支持拖過來(lái)也支持拖過去,那么ListBox就也能接收自身拖拽過來(lái)的文件
//為了防止鼠標(biāo)點(diǎn)擊和拖拽的沖突,需要屏蔽從程序自身拖拽過來(lái)的文件
//這里判斷文件是否從程序外部拖拽進(jìn)來(lái),也就是判斷圖片是否在工作目錄下
if (files.Length > 0 && !files[0].StartsWith(path) &&
(e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy)
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
foreach (string file in files)
{
try
{
//如果是從外部拖拽進(jìn)來(lái)的圖像,則復(fù)制該文件到工作目錄下做備份
string destFile = path System.IO.Path.GetFileName(file);
switch (e.Effects)
{
case DragDropEffects.Copy:
File.Copy(file, destFile, false);
bmi = new BitmapImage(new Uri(destFile));
imgShow.Source = bmi;
lstImage.Items.Add(destFile);
break;
default:
break;
}
}
catch
{
MessageBox.Show("已存在此文件或?qū)肓朔菆D像文件!");
}
}
}
private void lstImage_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.RightButton == MouseButtonState.Released)
{
bmi = new BitmapImage(new Uri(lstImage.SelectedItem.ToString()));
imgShow.Source = bmi;
}
}
private void lstImage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (lstImage.SelectedIndex > -1)
{
//只使用了Listbox單選功能
string[] files = new string[1];
files[0] = lstImage.SelectedItem.ToString();
DragDrop.DoDragDrop(lstImage, new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy | DragDropEffects.Move /* | DragDropEffects.Link */);
}
}
}
}
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Configuration;
using?System.Data;
using?System.Linq;
using?System.Windows;
namespace?ImageExplorer
{
????///?
????///?App.xaml?的交互邏輯
????///?
????public?partial?class?App?:?Application
????{
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????324??2013-05-28?14:44??ImageExplorer\ImageExplorer\App.xaml
?????文件????????309??2013-05-28?14:44??ImageExplorer\ImageExplorer\App.xaml.cs
?????文件??????11776??2013-05-29?14:51??ImageExplorer\ImageExplorer\bin\Debug\ImageExplorer.exe
?????文件??????30208??2013-05-29?14:51??ImageExplorer\ImageExplorer\bin\Debug\ImageExplorer.pdb
?????文件??????22472??2013-05-29?15:31??ImageExplorer\ImageExplorer\bin\Debug\ImageExplorer.vshost.exe
?????文件????????490??2012-06-02?22:34??ImageExplorer\ImageExplorer\bin\Debug\ImageExplorer.vshost.exe.manifest
?????文件???????4401??2013-05-28?15:14??ImageExplorer\ImageExplorer\ImageExplorer.csproj
?????文件????????884??2013-05-29?16:05??ImageExplorer\ImageExplorer\MainWindow.xaml
?????文件???????3967??2013-05-29?16:05??ImageExplorer\ImageExplorer\MainWindow.xaml.cs
?????文件???????2319??2013-05-28?15:14??ImageExplorer\ImageExplorer\obj\Debug\App.g.cs
?????文件???????2319??2013-05-28?15:58??ImageExplorer\ImageExplorer\obj\Debug\App.g.i.cs
?????文件???????7035??2013-05-29?16:05??ImageExplorer\ImageExplorer\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1009??2013-05-29?15:31??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.csproj.FileListAbsolute.txt
?????文件????????917??2013-05-28?15:00??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.csproj.GenerateResource.Cache
?????文件???????2501??2013-05-28?15:14??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.csprojResolveAssemblyReference.cache
?????文件??????11776??2013-05-29?14:51??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.exe
?????文件???????1465??2013-05-29?14:32??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.g.resources
?????文件??????30208??2013-05-29?14:51??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.pdb
?????文件????????180??2013-05-28?15:14??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer.Properties.Resources.resources
?????文件????????269??2013-05-29?14:51??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer_MarkupCompile.cache
?????文件????????268??2013-05-29?16:05??ImageExplorer\ImageExplorer\obj\Debug\ImageExplorer_MarkupCompile.i.cache
?????文件???????1237??2013-05-29?14:32??ImageExplorer\ImageExplorer\obj\Debug\MainWindow.baml
?????文件???????4659??2013-05-29?14:32??ImageExplorer\ImageExplorer\obj\Debug\MainWindow.g.cs
?????文件???????4659??2013-05-29?15:32??ImageExplorer\ImageExplorer\obj\Debug\MainWindow.g.i.cs
?????文件???????2179??2013-05-28?14:44??ImageExplorer\ImageExplorer\Properties\AssemblyInfo.cs
?????文件???????2878??2013-05-28?14:44??ImageExplorer\ImageExplorer\Properties\Resources.Designer.cs
?????文件???????5612??2013-05-28?14:44??ImageExplorer\ImageExplorer\Properties\Resources.resx
?????文件???????1100??2013-05-28?14:44??ImageExplorer\ImageExplorer\Properties\Settings.Designer.cs
?????文件????????201??2013-05-28?14:44??ImageExplorer\ImageExplorer\Properties\Settings.settings
?????文件????????929??2013-05-28?14:44??ImageExplorer\ImageExplorer.sln
............此處省略13個(gè)文件信息
- 上一篇:C# WPF 控件合集
- 下一篇:C#播放Mp3
評(píng)論
共有 條評(píng)論
相關(guān)資源
- 第二代Kinect WPF開發(fā)從入門到精通資料
- WPF21個(gè)優(yōu)秀項(xiàng)目及源碼
- SciChart控件破解方法見包內(nèi)
- WPF開發(fā)框架
- wpf特效輪播圖
- WPF做的監(jiān)控程序
- wpf 圖片滑動(dòng)效果
- Telerik_UI_for_WPF破解版
- Telerik_UI_for_WPF_2019_1_116_Dev.msi
- WPF編程寶典2012源碼和書(全)
- 深入淺出WPF劉鐵猛 重新整理書簽 帶源
- WPF程序設(shè)計(jì)指南完整PDF高清版
- Telerik UI for WPF 2018_1_116
- C#聯(lián)合halcon利用halcon控件實(shí)現(xiàn)鼠標(biāo)拖拽
- 深入淺出WPF 重新整理目錄,帶源碼
- Pro WPF 4.5 in C# Pro WPF系列第四版 英文書
- WPF學(xué)習(xí)書籍pdf《葵花寶典_WPF自學(xué)手冊(cè)
- Telerik_UI_for_WPF_Documentation
- WPF編程寶典C#2012 第4版(包含源碼)
- WPF編程寶典 第四版
- c# WPF 動(dòng)態(tài)曲線顯示
- WPF高級(jí)編程PDF
- WPF崩潰重啟
- C#/WPF下的通用自動(dòng)更新模塊修正
- 基于WPF的USB設(shè)備瀏覽器
- WPF實(shí)現(xiàn)類似安卓,ISO的日期選擇器
- WPF MVVM模式下 TreeView 右鍵菜單
- wpf入門第五篇 WPF with ECharts 項(xiàng)目源碼
- wpf界面與類之間的交互
- WPF自定義MessageBox完善版 v2 (源碼)