async Task <Bitmap> GetBitmap() { while (string.IsNullOrEmpty(pdf)) { var dialog = new CommonOpenFileDialog(); var filter = new CommonFileDialogFilter("PDF", "pdf"); dialog.Filters.Add(filter); if (dialog.ShowDialog() != CommonFileDialogResult.Ok) { Application.Current.Shutdown(); return(null); } pdf = dialog.FileName; } var image = await Task.Run(() => PDFUtility.GetImages(pdf)); pageIndex.Maximum = image.Count() - 1; var index = (int)pageIndex.Value; var bitmap = await Task.Run(() => new Bitmap(image.ToArray()[index].image)); return(bitmap); }
private async void btnAddFile_Click(object sender, EventArgs e) { CommonOpenFileDialog ofd = new CommonOpenFileDialog { Title = $"{this.Text}: {R.OpenFile}", DefaultDirectory = DefaultInputDirectory, InitialDirectory = Settings.InputDirectory, Multiselect = true, EnsurePathExists = true, EnsureFileExists = true, }; string[] filters = R.FilterAudibleFiles?.Split('|'); if (!(filters is null) && filters.Length % 2 == 0) { for (int i = 0; i < filters.Length; i += 2) { string filter = filters[i]; int pos = filter.IndexOf('('); if (pos >= 0) { filter = filter.Substring(0, pos); } var cfdf = new CommonFileDialogFilter(filter.Trim(), filters[i + 1].Trim()); ofd.Filters.Add(cfdf); } } CommonFileDialogResult result = ofd.ShowDialog(); if (result != CommonFileDialogResult.Ok) { return; } var filenames = ofd.FileNames; await addFilesAsync(filenames); }
/// <summary> /// Specifies a ONE File to be opened and populates the box with it. /// </summary> private void openToolStripMenuItem_Click(object sender, EventArgs e) { // Pick ONE file. CommonOpenFileDialog fileDialog = new CommonOpenFileDialog { Title = "Select the individual .ONE file to open.", Multiselect = false, IsFolderPicker = false, InitialDirectory = _lastOpenedDirectory }; CommonFileDialogFilter filter = new CommonFileDialogFilter("Sonic Heroes ONE Archive", ".one"); fileDialog.Filters.Add(filter); // Load it if selected. if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { // Reset archive, load new archive in. ResetONEArchive(); byte[] oneFile = File.ReadAllBytes(fileDialog.FileName); Archive = Archive.FromONEFile(ref oneFile); // Update the GUI UpdateGUI(ref Archive); SetCheckboxHint(ref oneFile); // Conditionally display Shadow the Edgehog warning. CheckShadowWarning(ref oneFile); // Set titlebar. this.titleBar_Title.Text = Path.GetFileName(fileDialog.FileName); _lastOpenedDirectory = Path.GetDirectoryName(fileDialog.FileName); _lastONEDirectory = Path.GetDirectoryName(fileDialog.FileName); } }
protected void AddFilter(DialogFilterPair filter) { var dialogFilter = new CommonFileDialogFilter(filter.DisplayName, filter.ExtensionsList); dialog.Filters.Add(dialogFilter); }
public void ShowFileOpenDialog() { string[] fileNames; List <Agent.KeyConstraint> constraints = new List <Agent.KeyConstraint>(); if (mAgent is PageantClient) { // Client Mode with Pageant - Show standard file dialog since we don't // need / can't use constraints using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Multiselect = true; openFileDialog.Filter = string.Join("|", Strings.filterPuttyPrivateKeyFiles, "*.ppk", Strings.filterAllFiles, "*.*"); var result = openFileDialog.ShowDialog(); if (result != DialogResult.OK) { return; } fileNames = openFileDialog.FileNames; } } else if (CommonOpenFileDialog.IsPlatformSupported) { // Windows Vista/7/8 has new style file open dialog that can be extended // using the Windows API via the WindowsAPICodepack library var win7OpenFileDialog = new CommonOpenFileDialog(); win7OpenFileDialog.Multiselect = true; win7OpenFileDialog.EnsureFileExists = true; var confirmConstraintCheckBox = new CommonFileDialogCheckBox(cConfirmConstraintCheckBox, "Require user confirmation"); var lifetimeConstraintTextBox = new CommonFileDialogTextBox(cLifetimeConstraintTextBox, string.Empty); lifetimeConstraintTextBox.Visible = false; var lifetimeConstraintCheckBox = new CommonFileDialogCheckBox(cLifetimeConstraintCheckBox, "Set lifetime (in seconds)"); lifetimeConstraintCheckBox.CheckedChanged += (s, e) => { lifetimeConstraintTextBox.Visible = lifetimeConstraintCheckBox.IsChecked; }; var confirmConstraintGroupBox = new CommonFileDialogGroupBox(); var lifetimeConstraintGroupBox = new CommonFileDialogGroupBox(); confirmConstraintGroupBox.Items.Add(confirmConstraintCheckBox); lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintCheckBox); lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintTextBox); win7OpenFileDialog.Controls.Add(confirmConstraintGroupBox); win7OpenFileDialog.Controls.Add(lifetimeConstraintGroupBox); var filter = new CommonFileDialogFilter( Strings.filterPuttyPrivateKeyFiles, "*.ppk"); win7OpenFileDialog.Filters.Add(filter); filter = new CommonFileDialogFilter(Strings.filterAllFiles, "*.*"); win7OpenFileDialog.Filters.Add(filter); win7OpenFileDialog.FileOk += win7OpenFileDialog_FileOk; /* add help listeners to win7OpenFileDialog */ // declare variables here so that the GC does not eat them. WndProcDelegate newWndProc, oldWndProc = null; win7OpenFileDialog.DialogOpening += (sender, e) => { var hwnd = win7OpenFileDialog.GetWindowHandle(); // hook into WndProc to catch WM_HELP, i.e. user pressed F1 newWndProc = (hWnd, msg, wParam, lParam) => { const short shellHelpCommand = 0x7091; var win32Msg = (Win32Types.Msg)msg; switch (win32Msg) { case Win32Types.Msg.WM_HELP: var helpInfo = (HELPINFO)Marshal.PtrToStructure(lParam, typeof(HELPINFO)); // Ignore if we are on an unknown control or control 100. // These are the windows shell control. The help command is // issued by these controls so by not ignoring, we would call // the help method twice. if (helpInfo.iCtrlId != 0 && helpInfo.iCtrlId != 100) { OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty); } return((IntPtr)1); // TRUE case Win32Types.Msg.WM_COMMAND: var wParamBytes = BitConverter.GetBytes(wParam.ToInt32()); var highWord = BitConverter.ToInt16(wParamBytes, 0); var lowWord = BitConverter.ToInt16(wParamBytes, 2); if (lowWord == 0 && highWord == shellHelpCommand) { OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty); return((IntPtr)0); } break; } return(CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam)); }; var newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc); var oldWndProcPtr = SetWindowLongPtr(hwnd, WindowLongFlags.GWL_WNDPROC, newWndProcPtr); oldWndProc = (WndProcDelegate) Marshal.GetDelegateForFunctionPointer(oldWndProcPtr, typeof(WndProcDelegate)); }; var result = win7OpenFileDialog.ShowDialog(); if (result != CommonFileDialogResult.Ok) { return; } if (confirmConstraintCheckBox.IsChecked) { var constraint = new Agent.KeyConstraint(); constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM; constraints.Add(constraint); } if (lifetimeConstraintCheckBox.IsChecked) { // error checking for parse done in fileOK event handler uint lifetime = uint.Parse(lifetimeConstraintTextBox.Text); var constraint = new Agent.KeyConstraint(); constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_LIFETIME; constraint.Data = lifetime; constraints.Add(constraint); } fileNames = win7OpenFileDialog.FileNames.ToArray(); } else { using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Multiselect = true; openFileDialog.Filter = string.Join("|", Strings.filterPuttyPrivateKeyFiles, "*.ppk", Strings.filterAllFiles, "*.*"); openFileDialog.FileOk += xpOpenFileDialog_FileOk; // Windows XP uses old style file open dialog that can be extended // using the Windows API via FileDlgExtenders library XPOpenFileDialog xpOpenFileDialog = null; if (Type.GetType("Mono.Runtime") == null) { xpOpenFileDialog = new XPOpenFileDialog(); xpOpenFileDialog.FileDlgStartLocation = AddonWindowLocation.Bottom; mOpenFileDialogMap.Add(openFileDialog, xpOpenFileDialog); } openFileDialog.HelpRequest += OnAddFromFileHelpRequested; // TODO: technically, a listener could be added after this openFileDialog.ShowHelp = AddFromFileHelpRequested != null; var result = xpOpenFileDialog == null? openFileDialog.ShowDialog() : openFileDialog.ShowDialog(xpOpenFileDialog, null); if (result != DialogResult.OK) { return; } if (xpOpenFileDialog == null) { // If dialog could not be extended, then we add constraints by holding // down the control key when clicking the Open button. if (Control.ModifierKeys.HasFlag(Keys.Control)) { var constraintDialog = new ConstraintsInputDialog(); constraintDialog.ShowDialog(); if (constraintDialog.DialogResult == DialogResult.OK) { if (constraintDialog.ConfirmConstraintChecked) { constraints.AddConfirmConstraint(); } if (constraintDialog.LifetimeConstraintChecked) { constraints.AddLifetimeConstraint(constraintDialog.LifetimeDuration); } } } } else { mOpenFileDialogMap.Remove(openFileDialog); if (xpOpenFileDialog.UseConfirmConstraintChecked) { constraints.AddConfirmConstraint(); } if (xpOpenFileDialog.UseLifetimeConstraintChecked) { constraints.AddLifetimeConstraint (xpOpenFileDialog.LifetimeConstraintDuration); } } fileNames = openFileDialog.FileNames; } } UseWaitCursor = true; mAgent.AddKeysFromFiles(fileNames, constraints); if (!(mAgent is Agent)) { ReloadKeyListView(); } UseWaitCursor = false; }
private void ReadAllSchoolSchedule() { //在rhjxx33.xls中每个人对应的一行单独制成一个WorkSheet(可怜的表呀,第一范式也不满足) //NO!!!!!!不制成WorkSheet使用List<List<string>>即二维字符串List //不对,用数组什么的就不能使行或列的表头有意义了,还有是用 //嗯。。。找到的更好的解决办法Dictionary CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog(); CommonFileDialogFilter filter = new CommonFileDialogFilter("*.xls文件", ".xls"); openFileDialog.Filters.Add(filter); CommonFileDialogResult commonFileDialogResult = CommonFileDialogResult.None; App.Current.Dispatcher.Invoke(new Action(() => { commonFileDialogResult = openFileDialog.ShowDialog(); })); if (commonFileDialogResult == CommonFileDialogResult.Ok) { allSchoolScheduleBW.ReportProgress(0); xlFilePath = openFileDialog.FileName; allSchoolScheduleApp = new Excel.Application(); //allSchoolScheduleApp.Visible = false; allSchoolScheduleWb = allSchoolScheduleApp.Workbooks.Open(xlFilePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); allSchoolScheduleWs = (Excel.Worksheet)allSchoolScheduleWb.Worksheets.get_Item(1); App.Current.Dispatcher.Invoke(new Action(() => { txtTextBox.Text += "====================\n" + "开始对文件 " + xlFilePath + "进行处理\n" + "====================\n"; txtTextBox.ScrollToEnd(); })); Excel.Range range; range = allSchoolScheduleWs.UsedRange; int rowCount, rCount, cCount; rCount = range.Rows.Count; cCount = range.Columns.Count; /* MessageBox.Show("rCount: " + rCount + * "cCount: " + cCount);*/ //这里先试试一个人的 string cellString = ""; string[] tempSplitArry; int tempWeek; //int tempYear = System.DateTime.Now.Year; Excel.Range tempResultRange; resultScheduleWb = allSchoolScheduleApp.Workbooks.Add(); resultScheduleWs = (Excel.Worksheet)resultScheduleWb.Worksheets.get_Item(1); /* 生成“排课结果” */ resultScheduleWs.Cells[1, 1] = "年级"; resultScheduleWs.Cells[1, 2] = "班级"; resultScheduleWs.Cells[1, 3] = "课程"; resultScheduleWs.Cells[1, 4] = "教师"; resultScheduleWs.Cells[1, 5] = "场地"; resultScheduleWs.Cells[1, 6] = "星期"; resultScheduleWs.Cells[1, 7] = "节次"; resultScheduleLineNum = 2; for (rowCount = 4; rowCount < rCount + 1; rowCount++) { App.Current.Dispatcher.Invoke(new Action(() => { txtTextBox.Text += "正在生成 " + range.Rows[rowCount].Columns[1].Value2.ToString() + " 的排课结果\n"; txtTextBox.ScrollToEnd(); })); //colCount = 2是为了避过姓名一列,colCount是从1号开始的cCount要加一 for (int colCount = 2; colCount < cCount + 1; colCount++) { if (range.Rows[rowCount].Columns[colCount].Value2 != null) { cellString = range.Rows[rowCount].Columns[colCount].Value2.ToString(); cellString = cellString.Replace("\n", "."); tempSplitArry = cellString.Split('.'); if (tempSplitArry.Length != 3) { MessageBox.Show("这个表不对头哦,只有班级没有学科!"); } //传地址了吗?忘了tempResultRange是干什么用的了 tempResultRange = resultScheduleWs.Rows[resultScheduleLineNum]; //写入“排课结果的年级、班级两列 switch (tempSplitArry[0]) { case "小六": tempResultRange.Columns[1].Value2 = "六年级"; tempResultRange.Columns[2].Value2 = "六年级(" + tempSplitArry[1] + ")"; break; case "小五": tempResultRange.Columns[1].Value2 = "五年级"; tempResultRange.Columns[2].Value2 = "五年级(" + tempSplitArry[1] + ")"; break; case "小四": tempResultRange.Columns[1].Value2 = "四年级"; tempResultRange.Columns[2].Value2 = "四年级(" + tempSplitArry[1] + ")"; break; case "小三": tempResultRange.Columns[1].Value2 = "三年级"; tempResultRange.Columns[2].Value2 = "三年级(" + tempSplitArry[1] + ")"; break; case "小二": tempResultRange.Columns[1].Value2 = "二年级"; tempResultRange.Columns[2].Value2 = "二年级(" + tempSplitArry[1] + ")"; break; case "小一": tempResultRange.Columns[1].Value2 = "一年级"; tempResultRange.Columns[2].Value2 = "一年级(" + tempSplitArry[1] + ")"; break; } //写入课程 tempResultRange.Columns[3].Value2 = tempSplitArry[2]; //写入教师 tempResultRange.Columns[4].Value2 = range.Rows[rowCount].Columns[1].Value2; //写入场地 tempResultRange.Columns[5].Value2 = "自动"; //写入星期 tempWeek = int.Parse(Math.Ceiling((colCount - 1F) / 6F).ToString()); switch (tempWeek) { case 1: tempResultRange.Columns[6].Value2 = "星期一"; break; case 2: tempResultRange.Columns[6].Value2 = "星期二"; break; case 3: tempResultRange.Columns[6].Value2 = "星期三"; break; case 4: tempResultRange.Columns[6].Value2 = "星期四"; break; case 5: tempResultRange.Columns[6].Value2 = "星期五"; break; } //写入节次 tempResultRange.Columns[7].Value2 = range.Rows[3].Columns[colCount].Value2; resultScheduleLineNum++; } } } CommonOpenFileDialog openFolderDialog = new CommonOpenFileDialog(); openFolderDialog.IsFolderPicker = true; openFolderDialog.Title = "选择文件保存目录"; //openFolderDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); commonFileDialogResult = CommonFileDialogResult.None; App.Current.Dispatcher.Invoke(new Action(() => { commonFileDialogResult = openFolderDialog.ShowDialog(); })); if (commonFileDialogResult == CommonFileDialogResult.Ok) { allSchoolScheduleBW.ReportProgress(100); string fileSavePath = openFolderDialog.FileName; System.DateTime dateTime = System.DateTime.Now; resultScheduleWb.SaveAs(fileSavePath + "\\排课结果" + dateTime.Year + dateTime.Month + dateTime.Day + dateTime.Hour + dateTime.Minute + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive); resultScheduleWb.Close(false); allSchoolScheduleWb.Close(false); allSchoolScheduleApp.Quit(); App.Current.Dispatcher.Invoke(new Action(() => { txtTextBox.Text += "====================\n" + "成功生成文件" + fileSavePath + "\\排课结果" + dateTime.Year + dateTime.Month + dateTime.Day + dateTime.Hour + dateTime.Minute + ".xls" + "====================\n"; txtTextBox.ScrollToEnd(); })); } else if (commonFileDialogResult == CommonFileDialogResult.Cancel) { App.Current.Dispatcher.Invoke(new Action(() => { txtTextBox.Text += "====================\n" + "排课结果 未保存\n" + "====================\n"; txtTextBox.ScrollToEnd(); })); } MessageBox.Show("Mission Accomplished!!!"); } }
public static string QueryUserForPath(string initialDirectory = "", string title = "", CommonFileDialogFilter filter = null) { var dialog = new CommonOpenFileDialog() { IsFolderPicker = true, }; //if (filter != null) //{ // dialog.Filters.Add(filter); //} if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } CommonFileDialogResult result; try { result = dialog.ShowDialog(); } catch (Exception e) { Console.WriteLine($"Error while reading directory path: {e.Message}"); return(null); } return(result == CommonFileDialogResult.Ok ? dialog.FileName : null); }
private async Task <string> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default) { var title = Title.Get(context); var defaultpath = InitialPath.Get(context); var result = string.Empty; var dlg = new CommonOpenFileDialog(); if (!string.IsNullOrEmpty(defaultpath)) { var index = defaultpath.LastIndexOf(@"\"); var dotindex = defaultpath.IndexOf(@".", index); if (dotindex < 0) { defaultpath = defaultpath + @"\"; } } if (!string.IsNullOrEmpty(title)) { dlg.Title = title; } if (!string.IsNullOrEmpty(Path.GetDirectoryName(defaultpath))) { dlg.InitialDirectory = Path.GetDirectoryName(defaultpath); } if (!string.IsNullOrEmpty(Path.GetFileName(defaultpath))) { dlg.DefaultFileName = Path.GetFileName(defaultpath); } if ((int)this.FileType >= 1) { var filter = new CommonFileDialogFilter(); filter.DisplayName = "許可されたファイル"; if (this.FileType.HasFlag(FileTypes.Excel)) { filter.Extensions.Add("xls"); filter.Extensions.Add("xlsx"); filter.Extensions.Add("xlsm"); } if (this.FileType.HasFlag(FileTypes.CSV)) { filter.Extensions.Add("csv"); } if (this.FileType.HasFlag(FileTypes.PDF)) { filter.Extensions.Add("pdf"); } if (this.FileType.HasFlag(FileTypes.Text)) { filter.Extensions.Add("txt"); } if (this.FileType.HasFlag(FileTypes.PowerPoint)) { filter.Extensions.Add("ppt"); filter.Extensions.Add("pptx"); } if (this.FileType.HasFlag(FileTypes.Word)) { filter.Extensions.Add("doc"); filter.Extensions.Add("docx"); } dlg.Filters.Add(filter); } else { dlg.Filters.Add(new CommonFileDialogFilter("すべてのファイル", "*.*")); } if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { result = dlg.FileName; } return(await Task.FromResult(result)); }