public void ExportAsCsvFile() { using (var rDialog = new CommonSaveFileDialog()) { rDialog.FileTypes.Add(new CommonFileDialogFileType(StringResources.Instance.Main.Export_CSV_FileType, "csv")); rDialog.DefaultExtension = "csv"; if (rDialog.Show(WindowUtil.GetTopWindow()) != CommonFileDialogResult.OK) { return; } var rFilename = rDialog.Filename; using (var rWriter = new StreamWriter(File.Open(rFilename, FileMode.Create), Encoding.Default)) ExportAsCsvFileCore(rWriter); var rButton = new TaskDialogButton(StringResources.Instance.Main.Export_CSV_Message_OpenFile); var rResult = new TaskDialog() { Caption = StringResources.Instance.Main.Product_Name, Icon = TaskDialogIcon.Information, Instruction = StringResources.Instance.Main.Export_CSV_Message, CommonButtons = TaskDialogCommonButtons.OK, Buttons = { rButton }, OwnerWindow = WindowUtil.GetTopWindow(), ShowAtTheCenterOfOwner = true, }.ShowAndDispose(); if (rResult.SelectedButton == rButton) { Process.Start(rFilename); } } }
public void TakeScreenshot(object rpTabControl) { var rTabControl = rpTabControl as Control; if (rTabControl == null) { return; } var rContent = rTabControl.Template.FindName("PART_SelectedContentHost", rTabControl) as ContentPresenter; if (rContent == null) { return; } var rRenderTargetBitmap = new RenderTargetBitmap((int)(rContent.ActualWidth * DpiUtil.ScaleX), (int)(rContent.ActualHeight * DpiUtil.ScaleY), DpiUtil.DpiX, DpiUtil.DpiY, PixelFormats.Pbgra32); rRenderTargetBitmap.Render(rContent); var rScreenshotFilename = string.Empty; var rOutputToFile = Preference.Instance.Game.CompositionSharing_OutputScreenshotToFile.Value; if (!rOutputToFile) { Clipboard.SetImage(rRenderTargetBitmap); } else { using (var rSaveDialog = new CommonSaveFileDialog()) { rSaveDialog.FileTypes.Add(new CommonFileDialogFileType("PNG", "png")); if (rSaveDialog.Show(WindowUtil.GetTopWindow()) == CommonFileDialogResult.Cancel) { return; } rScreenshotFilename = rSaveDialog.Filename; if (!rScreenshotFilename.OICEndsWith(".png")) { rScreenshotFilename += ".png"; } } using (var rFile = File.OpenWrite(rScreenshotFilename)) { var rEncoder = new PngBitmapEncoder() { Frames = { BitmapFrame.Create(rRenderTargetBitmap) } }; rEncoder.Save(rFile); } } var rDialog = new TaskDialog() { Caption = StringResources.Instance.Main.Window_CompositionSharing, Instruction = StringResources.Instance.Main.CompositionSharing_TakeScreenshot_Clipboard_Message, Icon = TaskDialogIcon.Information, OwnerWindow = WindowUtil.GetTopWindow(), ShowAtTheCenterOfOwner = true, }; if (!rOutputToFile) { rDialog.Instruction = StringResources.Instance.Main.CompositionSharing_TakeScreenshot_Clipboard_Message; } else { rDialog.Instruction = StringResources.Instance.Main.CompositionSharing_TakeScreenshot_File_Message; rDialog.EnableHyperlinks = true; rDialog.FooterIcon = TaskDialogIcon.Information; rDialog.Footer = $"<a href=\"{rScreenshotFilename}\">{rScreenshotFilename}</a>"; EventHandler <string> rHyperlinkClicked = null; rHyperlinkClicked = delegate { if (File.Exists(rScreenshotFilename)) { Process.Start(rScreenshotFilename); } }; EventHandler rClosed = null; rClosed = delegate { rDialog.HyperlinkClicked -= rHyperlinkClicked; rDialog.Closed -= rClosed; }; rDialog.HyperlinkClicked += rHyperlinkClicked; rDialog.Closed += rClosed; } rDialog.ShowAndDispose(); }