本文整理汇总了C#中Microsoft.Win32.SaveFileDialog类的典型用法代码示例。如果您正苦于以下问题:C# SaveFileDialog类的具体用法?C# SaveFileDialog怎么用?C# SaveFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SaveFileDialog类属于Microsoft.Win32命名空间,在下文中一共展示了SaveFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveImageCapture
public static void SaveImageCapture(BitmapSource bitmap)
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.QualityLevel = 100;
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Image"; // Default file name
dlg.DefaultExt = ".Jpg"; // Default file extension
dlg.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save Image
string filename = dlg.FileName;
FileStream fstream = new FileStream(filename, FileMode.Create);
encoder.Save(fstream);
fstream.Close();
}
}
示例2: SaveProject
public void SaveProject()
{
string fileToSave = null;
if (string.IsNullOrEmpty(ArrowState.Self.CurrentGluxFileLocation))
{
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Filter = "*.arox|*.arox";
var result = fileDialog.ShowDialog();
if (result.HasValue && result.Value)
{
fileToSave = fileDialog.FileName;
ArrowState.Self.CurrentGluxFileLocation = fileToSave;
}
}
else
{
fileToSave = ArrowState.Self.CurrentGluxFileLocation;
}
if (!string.IsNullOrEmpty(fileToSave))
{
FileManager.XmlSerialize(ArrowState.Self.CurrentArrowProject, fileToSave);
}
}
示例3: Export
private void Export(object param)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = String.Format("{0} files|*.{1}|{2} files|*.{3}", "Pdf", "pdf", "Text", "txt");
if (dialog.ShowDialog() == true)
{
using (var stream = dialog.OpenFile())
{
RadFixedDocument document = this.CreateDocument();
switch (dialog.FilterIndex)
{
case 1:
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
pdfFormatProvider.Export(document, stream);
break;
case 2:
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
{
TextFormatProvider textFormatProvider = new TextFormatProvider();
writer.Write(textFormatProvider.Export(document));
}
break;
}
}
}
}
示例4: CreatePuzzleButton_OnClick
private void CreatePuzzleButton_OnClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_filename))
{
MessageBox.Show("Image does not selected!");
return;
}
var filePath = _filename;
var x = XBlocksCount;
var y = YBlocksCount;
var generator = new PuzzleCreator(filePath);
var images = generator.GetMixedPartsOfImage(x, y);
Bitmap bitmap = generator.GenerateBitmap(images, x, y);
var saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "puzzle";
saveFileDialog.DefaultExt = ".jpg";
saveFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.png) | *.jpg; *.jpeg; *.png";
Nullable<bool> result = saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
{
bitmap.Save(saveFileDialog.FileName);
}
else
{
MessageBox.Show("Puzzle does not saved!");
}
}
示例5: Export
private static void Export()
{
var saveFileDialog = new SaveFileDialog { Filter = "CSV files (*.csv)|*.csv" };
if (saveFileDialog.ShowDialog() == true)
{
try
{
using (Stream stream = new FileStream(saveFileDialog.FileName, FileMode.Create))
{
_grid.Export(stream, new GridViewCsvExportOptions
{
ColumnDelimiter = CultureInfo.CurrentCulture.TextInfo.ListSeparator,
ShowColumnHeaders = true,
ShowColumnFooters = false,
ShowGroupFooters = false,
Culture = CultureInfo.CurrentCulture,
Encoding = Encoding.UTF8,
Items = (IEnumerable)_grid.ItemsSource
});
}
}
catch (IOException)
{
MessageBox.Show(String.Format(
"Export to file {0} was failed. File used by another process. End process and try again.",
saveFileDialog.FileName), "Error");
}
}
}
示例6: ExportToCSV
//Exports the data from the output window to a csv file
public void ExportToCSV()
{
try
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "CSV|*.csv";
saveFileDialog1.Title = "Export to CSV";
string currentDateTime = DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss");
saveFileDialog1.FileName = currentDateTime;
Nullable<bool> saveFileResult = saveFileDialog1.ShowDialog();
//If saveFileResut is null (user clicked cancel) then do nothing
if (saveFileResult == false)
{
return;
}
//Copy the temporary file with the ping data to a csv file
else
{
File.Copy(_temporaryPingDataFile, saveFileDialog1.FileName);
}
}
catch (Exception er)
{
MessageBox.Show("Error with filename" + Environment.NewLine + Environment.NewLine + er);
return;
}
}
示例7: Save
// yuehan start: 保存 baml 到 xaml 文件
public override bool Save(DecompilerTextView textView)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = Path.GetFileName(DecompilerTextView.CleanUpName(base.Text as string));
dlg.FileName = Regex.Replace(dlg.FileName, @"\.baml$", ".xaml", RegexOptions.IgnoreCase);
if (dlg.ShowDialog() == true)
{
// 反编译 baml 文件
var baml = this.Data;
var asm = this.Ancestors().OfType<AssemblyTreeNode>().FirstOrDefault().LoadedAssembly;
baml.Position = 0;
var doc = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, baml);
var xaml = doc.ToString();
// 保存 xaml
FileInfo fi = new FileInfo(dlg.FileName);
if (fi.Exists) fi.Delete();
using (var fs = fi.OpenWrite())
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(xaml);
sw.Flush();
sw.Close();
}
}
return true;
}
示例8: OnInitialized
/// <summary>
/// Invoked when the window is initialized.
/// </summary>
/// <param name="e">Empty EventArgs instance.</param>
protected override void OnInitialized(EventArgs e)
{
this.importDialog = (OpenFileDialog)this.Resources["importDialog"];
this.saveDialog = (SaveFileDialog)this.Resources["saveDialog"];
this.imageList.ItemsSource = this.currentIcon.Images;
base.OnInitialized(e);
}
示例9: Execute
public void Execute(object parameter)
{
var exportObject = new ExportData();
using (var irep=_itemsRepos())
{
exportObject.EveItems = irep.GetAll().ToArray();
}
using (var brep=_blueprintsRepos())
{
exportObject.Blueprints = brep.GetAll().ToArray();
}
using (var prep=_prodinfoRepos())
{
exportObject.ProductionInfos = prep.GetAll().ToArray();
}
var res = JsonConvert.SerializeObject(exportObject,Formatting.Indented);
var dlg = new SaveFileDialog()
{
Title = "Экспорт БД",
Filter = "Data File *.dat|*.dat"
};
if (dlg.ShowDialog() == true)
{
using (var writer=File.CreateText(dlg.FileName))
{
writer.Write(res);
writer.Close();
}
}
}
示例10: SaveGame
public string SaveGame(IClearMine game, string path = null)
{
if (game == null)
throw new ArgumentNullException("game");
if (String.IsNullOrWhiteSpace(path))
{
var savePathDialog = new SaveFileDialog();
savePathDialog.DefaultExt = Settings.Default.SavedGameExt;
savePathDialog.Filter = ResourceHelper.FindText("SavedGameFilter", Settings.Default.SavedGameExt);
if (savePathDialog.ShowDialog() == true)
{
path = savePathDialog.FileName;
}
else
{
return null;
}
}
// Pause game to make sure the timestamp correct.
game.PauseGame();
var gameSaver = new XmlSerializer(game.GetType());
using (var file = File.Open(path, FileMode.Create, FileAccess.Write))
{
gameSaver.Serialize(file, game);
}
game.ResumeGame();
return path;
}
示例11: Button1_Click
private void Button1_Click(object sender, RoutedEventArgs e)
{
var pageSize = this.pager.PageSize;
var pageIndex = this.pager.PageIndex;
this.pager.PageIndex = 0;
this.pager.PageSize = 0;
string extension = "xlsx";
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{
using (Stream stream = dialog.OpenFile())
{
this.clubsGrid.ExportToXlsx(stream);
}
}
this.pager.PageSize = pageSize;
this.pager.PageIndex = pageIndex;
}
示例12: Save
void Save()
{
try
{
string date = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.AddExtension = true;
saveFile.Filter = "Text documents (.txt)|*.txt";
saveFile.DefaultExt = ".txt";
saveFile.FileName = "Folder_Rename_Save " + date;
bool? result = saveFile.ShowDialog();
if (result == true)
{
string contents = "";
foreach (string ligne in listeAvancement)
{
contents += ligne + "\r\n";
}
File.WriteAllText(saveFile.FileName, contents);
}
}
catch { }
}
示例13: btnExtractImage_Click
private void btnExtractImage_Click(object sender, RoutedEventArgs e)
{
try
{
_blf = new PureBLF(_blfLocation);
var sfd = new SaveFileDialog
{
Title = "Save the extracted BLF Image",
Filter = "JPEG Image (*.jpg)|*.jpg",
FileName = lblBLFname.Text.Replace(".blf", "")
};
if (!((bool)sfd.ShowDialog()))
{
Close();
return;
}
var imageToExtract = new List<byte>(_blf.BLFChunks[1].ChunkData);
imageToExtract.RemoveRange(0, 0x08);
File.WriteAllBytes(sfd.FileName, imageToExtract.ToArray<byte>());
MetroMessageBox.Show("Exracted!", "The BLF Image has been extracted.");
Close();
}
catch (Exception ex)
{
Close();
MetroMessageBox.Show("Extraction Failed!", "The BLF Image failed to be extracted: \n " + ex.Message);
}
}
示例14: Execute
public void Execute(ICSharpCode.TreeView.SharpTreeNode[] selectedNodes)
{
//Gets the loaded assembly
var loadedAssembly = ((AssemblyTreeNode)selectedNodes[0]).LoadedAssembly;
//Shows the dialog
var dialog = new SaveFileDialog()
{
AddExtension = false,
Filter = "Patched version of " + loadedAssembly.AssemblyDefinition.Name.Name + "|*.*",
FileName = Path.GetFileName(Path.ChangeExtension(loadedAssembly.FileName, ".Patched" + Path.GetExtension(loadedAssembly.FileName))),
InitialDirectory = Path.GetDirectoryName(loadedAssembly.FileName),
OverwritePrompt = true,
Title = "Save patched assembly"
};
if (dialog.ShowDialog().GetValueOrDefault(false))
{
//Writes the assembly
loadedAssembly.AssemblyDefinition.Write(dialog.FileName);
//Clears the coloring of the nodes
foreach (var x in Helpers.PreOrder(selectedNodes[0], x => x.Children))
x.Foreground = GlobalContainer.NormalNodesBrush;
var normalColor = ((SolidColorBrush)GlobalContainer.NormalNodesBrush).Color;
MainWindow.Instance.RootNode.Foreground =
MainWindow.Instance.RootNode.Children.All(x => x.Foreground is SolidColorBrush && ((SolidColorBrush)x.Foreground).Color == normalColor)
? GlobalContainer.NormalNodesBrush
: GlobalContainer.ModifiedNodesBrush;
}
}
示例15: Execute
public override void Execute(object parameter)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Database file (*.db3) |*.db3";
if (sfd.ShowDialog() == true)
{
SqliteDataProvider dataProvider = new SqliteDataProvider();
dataProvider.Open(sfd.FileName);
// string sql = "CREATE TABLE Fossils (id INTEGER PRIMARY KEY AUTOINCREMENT, fossilname TEXT, Descrip TEXT, area REAL, circularity REAL, elongation REAL, perimeter REAL, irregularity REAL , bitmap BLOB)";
string sql = "CREATE TABLE Authors (Author_id INTEGER PRIMARY KEY AUTOINCREMENT, Author_name TEXT)";
dataProvider.ExecuteNonQuery(sql);
string sql1 = "CREATE TABLE Description (Description_id INTEGER PRIMARY KEY AUTOINCREMENT, synonymy TEXT, shell TEXT, init_shell TEXT, crop TEXT, key_edge TEXT, front_end TEXT, rear_end TEXT, ventral_margin TEXT, growth_lines TEXT, sculpture TEXT, compare TEXT)";
dataProvider.ExecuteNonQuery(sql1);
string sql2 = "CREATE TABLE Genus (genus_id INTEGER PRIMARY KEY AUTOINCREMENT, genus_name TEXT)";
dataProvider.ExecuteNonQuery(sql2);
string sql3 = "CREATE TABLE GenusToAuthor (genus_id INTEGER, author_id INTEGER)";
dataProvider.ExecuteNonQuery(sql3);
string sql4 = "CREATE TABLE Parameters (parameters_id INTEGER PRIMARY KEY AUTOINCREMENT, init_shell TEXT, front_rear_end TEXT, age TEXT, length TEXT, sculpture TEXT, h_l REAL)";
dataProvider.ExecuteNonQuery(sql4);
string sql5 = "CREATE TABLE Photo (id INTEGER PRIMARY KEY AUTOINCREMENT, square REAL, vertex_x REAL, vertex_y REAL, furrow REAL, bitmap BLOB)";
dataProvider.ExecuteNonQuery(sql5);
string sql6 = "CREATE TABLE Species (species_id INTEGER PRIMARY KEY AUTOINCREMENT,species_name TEXT, genus_id INTEGER, description_id INTEGER)";
dataProvider.ExecuteNonQuery(sql6);
string sql7 = "CREATE TABLE SpeciesToAuthor (species_id INTEGER, author_id INTEGER)";
dataProvider.ExecuteNonQuery(sql7);
string sql8 = "CREATE TABLE Mollusk (mollusk_id INTEGER PRIMARY KEY AUTOINCREMENT, species_id INTEGER, photo_id INTEGER, parameters_id INTEGER)";
dataProvider.ExecuteNonQuery(sql8);
UIManager.man.Provider = dataProvider;
}
}