本文整理汇总了C#中OpenFileDialog类的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog类的具体用法?C# OpenFileDialog怎么用?C# OpenFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenFileDialog类属于命名空间,在下文中一共展示了OpenFileDialog类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MainWindow
public MainWindow()
{
InitializeComponent();
openFolderDialog = new FolderBrowserDialog();
openFolderDialog.Description = "Podaj katalog z przykładami";
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "*JPEG|*.jpg|Wszystkie pliki|*.*";
openFileDialog.Title = "Podaj plik przeznaczony do rozponania";
ojIterations = 10;
iterationsText.Text = ojIterations.ToString();
printLineDelegate = printByDispatcher;
saveImagesDelegate = saveImages;
createLearningExamplesDelegate = createLearningExamples;
getFilesDelegate = getFiles;
setExamplesDelegate = setExamples;
OnStateChange = stateChange;
OnReductionFinished = reductionFinished;
OnReductionStarted = reductionStarted;
files = null;
learnButton.IsEnabled = false;
compareButton.IsEnabled = false;
outputDimension = 7;
dimensionText.Text = outputDimension.ToString();
dataBaseFileName = "C:\\database.db";
dataBasePathText.Text = dataBaseFileName;
getDataBaseFileNameDelegate += DBFN;
examplesHeight = 0;
examplesWidth = 0;
}
开发者ID:robwoj,项目名称:sieci-neuronowe,代码行数:32,代码来源:MainWindow.xaml.cs
示例2: Button_Click_1
//导入“1300000 "北京市" "联通"”文本格式数据
private void Button_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt";
if (ofd.ShowDialog() == false)
{
return;
}
string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray();
for (int i = 1; i < lines.Count(); i++)
{
string line = lines[i];
string[] str = line.Split('\t');
string startTeLNum = str[0];
string city = str[1];
city = city.Trim('"');
string telType = str[2];
telType = telType.Trim('"');
SqlHelper.ExecuteQuery(@"Insert into T_TelNum(StartTelNum,TelType,TelArea)
values(@StartTelNum,@TelType,@TelArea)",
new SqlParameter("@StartTelNum", startTeLNum),
new SqlParameter("@TelType", telType),
new SqlParameter("@TelArea", city));
}
MessageBox.Show("导入成功!"+lines.Count()+"条数据");
}
开发者ID:kai2008009,项目名称:ADO.NET,代码行数:29,代码来源:导入数据.xaml.cs
示例3: Add
private void Add()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = ".dll";
ofd.Filter = "*.dll|*.dll";
if (ofd.ShowDialog() == true)
{
var types =
App.Pyrite.ModulesControl.RegisterChecker(ofd.FileName).Value.ToList().Union(
App.Pyrite.ModulesControl.RegisterAction(ofd.FileName).Value.ToList()
);
if (types.Count() == 0)
{
System.Windows.MessageBox.Show("Ни одного типа не зарегистрировано");
}
else
{
var str = "Зарегистрированы следующие типы: ";
foreach (var typeName in types.Select(x => x.Name))
{
str += "\r\n" + typeName;
}
System.Windows.MessageBox.Show(str);
}
}
Refresh();
lvDlls.SelectedItem = ofd.FileName;
App.Pyrite.CommitChanges();
}
开发者ID:noant,项目名称:Pyrite,代码行数:33,代码来源:ModulesControlView.xaml.cs
示例4: btnPopupLoadFile_Click
private void btnPopupLoadFile_Click(object sender, RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog { Multiselect = false };
var ftoload = fileDialog.ShowDialog(this);
if (ftoload.Value)
{
try
{
var tabs = JObject.Parse(File.ReadAllText(fileDialog.FileName))["tabs"] as JArray;
List<StashBookmark> tabb = new List<StashBookmark>();
foreach (JObject tab in tabs)
{
string name = tab["n"].Value<string>();
int index = tab["i"].Value<int>();
var c = tab["colour"].Value<JObject>();
var color = Color.FromArgb(0xFF, c["r"].Value<byte>(), c["g"].Value<byte>(), c["b"].Value<byte>());
StashBookmark sb = new StashBookmark(name, index, color);
tabb.Add(sb);
}
Tabs = tabb;
cbTabs.SelectedIndex = 0;
}
catch (Exception ex)
{
Popup.Error(L10n.Message("An error occurred while attempting to load stash data."), ex.Message);
}
}
}
开发者ID:Daendaralus,项目名称:PoESkillTree,代码行数:32,代码来源:DownloadStashWindow.xaml.cs
示例5: SelectFile
private void SelectFile(object sender, RoutedEventArgs e)
{
SoundItem soundItem = DataContext as SoundItem;
if (soundItem == null)
return;
string oldPath = soundItem.FilePath;
// Open a dialog to have the user pick a file.
// NOTE: I made a default filter for WAV files but for all I know the
// SoundPlayer class will play others. I added the "All files" filter
// for this situation.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select .wav file";
ofd.Filter = "WAV files (*.wav)|*.wav|All files (*.*)|*.*";
ofd.Multiselect = false;
DirectoryInfo di = SoundController.GetSoundProfileDirectory();
ofd.InitialDirectory = di.FullName;
bool? result = ofd.ShowDialog();
// If the user canceled or otherwise exited, do nothing.
if (result == null || result == false)
return;
// Set the new path and submit it for loading.
soundItem.FilePath = ofd.FileName;
if (soundItem.Submit() != Status.Success)
{
soundItem.FilePath = oldPath;
}
}
开发者ID:Rampant-ai,项目名称:Senesco,代码行数:33,代码来源:SoundItemControl.xaml.cs
示例6: CustomButtonClick
public void CustomButtonClick()
{
var openDialog = new OpenFileDialog
{
CheckFileExists = true,
Filter = "Sitecore Package or ZIP Archive (*.zip)|*.zip",
Title = "Choose Package",
Multiselect = true
};
if (openDialog.ShowDialog(Window.GetWindow(this)) == true)
{
foreach (string path in openDialog.FileNames)
{
var fileName = Path.GetFileName(path);
if (string.IsNullOrEmpty(fileName))
{
continue;
}
FileSystem.FileSystem.Local.File.Copy(path, Path.Combine(ApplicationManager.ConfigurationPackagesFolder, fileName));
var products = this.checkBoxItems.Where(item => !item.Name.Equals(fileName, StringComparison.OrdinalIgnoreCase)).ToList();
products.Add(new ProductInCheckbox(Product.GetFilePackageProduct(Path.Combine(ApplicationManager.ConfigurationPackagesFolder, fileName))));
this.checkBoxItems = new ObservableCollection<ProductInCheckbox>(products);
this.unfilteredCheckBoxItems = new ObservableCollection<ProductInCheckbox>(products);
this.filePackages.ItemsSource = this.checkBoxItems;
this.SelectAddedPackage(fileName);
}
}
}
开发者ID:Sitecore,项目名称:Sitecore-Instance-Manager,代码行数:32,代码来源:ConfigurationPackages.xaml.cs
示例7: Load_File
internal async Task Load_File(CancellationToken cancellation, IProgress<Tuple<string, int>> currentTaskAndPercentComplete)
{
if (UnsavedChangesPresent && !_window.Confirm_Discard_Changes()) return;
var dialog = new OpenFileDialog
{
DefaultExt = DataFileExt,
Filter = DataFileFilter
};
if (dialog.ShowDialog() ?? false)
{
FileList = await FileAccess.LoadInfo(dialog.FileName, cancellation, currentTaskAndPercentComplete);
if (cancellation.IsCancellationRequested)
{
return;
}
UnsavedChangesPresent = false;
if (FileList.Any())
{
FileIndex = 0;
RectangleIndex = 0;
RectangleHasFocus = false;
await _window.Canvas.LoadImage(this, FileIndex);
_window.Canvas.LoadRectangles(this, FileIndex);
}
}
}
开发者ID:zbxzc35,项目名称:Classifier,代码行数:28,代码来源:WindowData.cs
示例8: OpenDDL_Click
private void OpenDDL_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = null;
try
{
dialog = new OpenFileDialog();
dialog.CheckFileExists = true;
dialog.CheckPathExists = true;
dialog.Filter = "MigraDoc DDL (*.mdddl)|*.mdddl|All Files (*.*)|*.*";
dialog.FilterIndex = 1;
dialog.InitialDirectory = System.IO.Path.Combine(GetProgramDirectory(), "..\\..");
//dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == true)
{
Document document = DdlReader.DocumentFromFile(dialog.FileName);
string ddl = DdlWriter.WriteToString(document);
preview.Ddl = ddl;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Title);
preview.Ddl = null; // TODO has no effect
}
finally
{
//if (dialog != null)
// dialog.Dispose();
}
//UpdateStatusBar();
}
开发者ID:vronikp,项目名称:EventRegistration,代码行数:31,代码来源:MainWindow.xaml.cs
示例9: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.FileOk += Dlg_FileOk;
dlg.Filter = "*.jpg|*.jpg";
dlg.ShowDialog();
}
开发者ID:jakforest,项目名称:WCFImage,代码行数:7,代码来源:ViewImagePage.xaml.cs
示例10: AddCellButton_Click
private void AddCellButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
// Create an instance of the open file dialog box.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// Set filter options and filter index.
openFileDialog1.DefaultExt = ".000";
openFileDialog1.Filter = "S57 Cells (.000)|*.000";
openFileDialog1.Multiselect = true;
// Call the ShowDialog method to show the dialog box.
bool? userClickedOK = openFileDialog1.ShowDialog();
// Process input if the user clicked OK.
if (userClickedOK == true)
{
foreach (string fileName in openFileDialog1.FileNames)
{
var hydroLayer = new HydrographicS57Layer()
{
Path = fileName,
ID = Path.GetFileNameWithoutExtension(fileName)
};
_hydrographicGroupLayer.ChildLayers.Add(hydroLayer);
s57CellList.SelectedItem = hydroLayer;
}
}
}
开发者ID:MagicWang,项目名称:arcgis-runtime-samples-dotnet,代码行数:28,代码来源:S57CellInfoSample.xaml.cs
示例11: OpenMenuItem_Click
private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
{
if (asm != null && asm.Strings.Any(s => s.IsDirty))
{
if (MessageBox.Show("You have unsaved changes. Really open a new file?", Title, MessageBoxButton.YesNo) == MessageBoxResult.No)
return;
}
var ofd = new OpenFileDialog();
if (ofd.ShowDialog() != true)
return;
try
{
using (var f = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read))
{
DataContext = asm = CompiledAssembly.Load(f);
}
}
catch (Exception ex)
{
MessageBox.Show($"Could not open file: {ex}");
}
}
开发者ID:Xcelled,项目名称:net-string-editor,代码行数:25,代码来源:MainWindow.xaml.cs
示例12: MenuItem_Click
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
// 画像を開く
var dialog = new OpenFileDialog();
dialog.Filter = "画像|*.jpg;*.jpeg;*.png;*.bmp";
if (dialog.ShowDialog() != true)
{
return;
}
// ファイルをメモリにコピー
var ms = new MemoryStream();
using (var s = new FileStream(dialog.FileName, FileMode.Open))
{
s.CopyTo(ms);
}
// ストリームの位置をリセット
ms.Seek(0, SeekOrigin.Begin);
// ストリームをもとにBitmapImageを作成
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = ms;
bmp.EndInit();
// BitmapImageをSourceに指定して画面に表示する
this.image.Source = bmp;
}
开发者ID:runceel,项目名称:samples,代码行数:26,代码来源:MainWindow.xaml.cs
示例13: SetMode
private void SetMode()
{
if(IsFileSelector)
{
ButtonText = "\uF15C";
ButtonCommand = new RelayCommand(() =>
{
var dlg = new OpenFileDialog();
if (dlg.ShowDialog() == true)
{
ConfigItemValue = dlg.FileName;
}
}, true);
}
else
{
ButtonText = "\uF07C";
ButtonCommand = new RelayCommand(() =>
{
var dlg = new System.Windows.Forms.FolderBrowserDialog();
dlg.ShowNewFolderButton = true;
dlg.ShowDialog();
if (!String.IsNullOrEmpty(dlg.SelectedPath))
{
ConfigItemValue = dlg.SelectedPath;
}
}, true);
}
}
开发者ID:llenroc,项目名称:sharpDox,代码行数:29,代码来源:ConfigFileSystemControl.xaml.cs
示例14: OpenFile
/**
* <summary>Zeigt OpenFileDialog an</summary>
*
* <remarks>Beate, 09.10.2013.</remarks>
*/
private static string OpenFile()
{
string[] allfiles = { };
string filename = string.Empty;
string path = string.Empty;
List<string> filenameOnly = new List<string>();
OpenFileDialog inputDlg = new OpenFileDialog();
inputDlg.Multiselect = true;
inputDlg.InitialDirectory = @"";
inputDlg.Filter = "Xmascup Competitor Dateien|Competitor*.xml";
if (inputDlg.ShowDialog().Value)
{
allfiles = inputDlg.FileNames;
foreach (string s in allfiles)
{
filename = System.IO.Path.GetFileName(s);
path = System.IO.Path.GetDirectoryName(s);
filenameOnly.Add(filename);
}
MessageBox.Show("Eingabe: " + filename,
"Xmascup Dateiauswahl");
return allfiles[0].ToString();
}
else
{
MessageBox.Show("Keine Datei ausgewählt !!",
"Xmascup Dateiauswahl");
return "keine Auswahl getroffen";
}
}
开发者ID:hrherbie,项目名称:Xmascup,代码行数:38,代码来源:MainWindow.xaml.cs
示例15: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
openfiledialog.ShowDialog();
//if(openfiledialog.FileOk)
// System.IO.Stream fileStream = openfiledialog.FileOk;
}
开发者ID:hkalyan,项目名称:WpfApplication1,代码行数:7,代码来源:MainWindow.xaml.cs
示例16: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.ShowDialog();
if (fileDialog.FileName == string.Empty)
{
return;
}
var titleDialog = new ImageTitleDialogBox();
titleDialog.Owner = this;
var result = titleDialog.ShowDialog();
if (result != true)
{
return;
}
var newImage = new ImageViewModel()
{
Title = titleDialog.tbImageTitle.Text,
Source = fileDialog.FileName
};
var viewModel = (ImageGalleryViewModel)DataContext;
if (viewModel.CurrentAlbum.AddImage.CanExecute(null))
{
viewModel.CurrentAlbum.AddImage.Execute(newImage);
}
}
开发者ID:krstan4o,项目名称:TelerikAcademy,代码行数:30,代码来源:MainWindow.xaml.cs
示例17: btnRun_Click
private void btnRun_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Programs|*.exe|All files|*.*";
dlg.DefaultExt = ".exe";
if (!(dlg.ShowDialog() ?? false))
return;
string path = dlg.FileName;
// remove UI before disposing profiler
//this.timeLine.ValuesList.Clear();
if (this.provider != null)
this.provider.Close();
if (this.profiler != null)
this.profiler.Dispose();
string pathToDb = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Profiler.Controller.Profiler).Assembly.Location), "output.sdps");
if (File.Exists(pathToDb))
File.Delete(pathToDb);
this.database = new TempFileDatabase();
this.profiler = new Profiler.Controller.Profiler(path, database.GetWriter(), new ProfilerOptions());
profiler.RegisterFailed += delegate { MessageBox.Show("register failed"); };
profiler.DeregisterFailed += delegate { MessageBox.Show("deregister failed"); };
this.profiler.OutputUpdated += profiler_OutputUpdated;
this.profiler.SessionEnded += profiler_SessionEnded;
this.profiler.Start();
this.btnRun.IsEnabled = false;
this.btnStop.IsEnabled = true;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:35,代码来源:Window1.xaml.cs
示例18: AddImageMenuItem_Click
private void AddImageMenuItem_Click(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
InitialDirectory = @"C:\Users\Dmitry\Pictures",
FilterIndex = 2,
RestoreDirectory = true
};
if (openFileDialog.ShowDialog() != null)
{
try
{
var image = new BitmapImage(new Uri(openFileDialog.FileName));
if(_height == 0)
{
_height = image.PixelHeight;
_width = image.PixelWidth;
_pixelsNumber = _width*_height;
}
_standardImages.Add(image);
_standardImageVectors.Add(GetImageVector(BitmapConverter.BitmapImage2Bitmap(image)));
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
开发者ID:drodov,项目名称:DPSI,代码行数:29,代码来源:MainWindow.xaml.cs
示例19: LoadImage
public void LoadImage()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Bitmap Image (.bmp)|*.bmp|PNG Image (.png)|*.png|JPEG Image (.jpeg)|*.jpeg|JPG Image (.jpg)|*.jpg";
bool? result = ofd.ShowDialog();
string fileName = "";
if (result != null)
fileName = ofd.FileName;
if (fileName == "")
return;
canvas.Children.Clear();
BitmapImage image;
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
stream.Position = 0;
image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
}
canvas.Background = new ImageBrush(image);
}
开发者ID:Exellion,项目名称:Paint,代码行数:27,代码来源:ImageHandler.cs
示例20: OpenFileMenuItem_Click
private void OpenFileMenuItem_Click(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
InitialDirectory = @"C:\Users\Dmitry\Pictures",
FilterIndex = 2,
RestoreDirectory = true
};
if (openFileDialog.ShowDialog() != null)
{
try
{
_sourceImage = new BitmapImage(new Uri(openFileDialog.FileName));
_noisedImage = _sourceImage;
SourceImage.Source = _sourceImage;
_width = _sourceImage.PixelWidth;
_height = _sourceImage.PixelHeight;
_pixelsNumber = _width * _height;
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
开发者ID:drodov,项目名称:DPSI,代码行数:26,代码来源:MainWindow.xaml.cs
注:本文中的OpenFileDialog类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论