private void btnOK_Click(object sender, EventArgs e) { // データチェック if (!Directory.Exists(txtSaveDirectory.Text)) { var err = new StringBuilder(); err.AppendLine(@"以下のフォルダは存在しません。作成しますか?"); err.Append(txtSaveDirectory.Text); var result = MessageBox.Show( err.ToString(), @"保存先フォルダ", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (result == DialogResult.Yes) { Directory.CreateDirectory(txtSaveDirectory.Text); } else if (result == DialogResult.No) { MessageBox.Show(@"「保存先ディレクトリ」には存在するフォルダを指定してください。"); return; } else { return; } } if (IsInvalidFileNameFormat()) { MessageBox.Show( @"ファイル名のフォーマットが間違っています。", @"ファイル名", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Option.Instance().SaveDirectory = txtSaveDirectory.Text; Option.Instance().FileNameFormat = txtFileNameFormat.Text; Option.Instance().ImageFormat = ((KeyValuePair <string, ImageFormat>)cmbImageFormat.SelectedItem).Value; // 後処理 // op.DoAfterProcessing = chkDoAfterProcessing.Checked; // op.DoResize = chkDoResize.Checked; // op.WidthBiggerSrc = int.Parse(txtWidthBiggerSrc.Text); // op.WidthBiggerDest = int.Parse(txtWidthBiggerDest.Text); // op.WidthLessSrc = int.Parse(txtWidthLessSrc.Text); // op.WidthLessDest = int.Parse(txtWidthLessDest.Text); // op.HeightBiggerSrc = int.Parse(txtHeightBiggerSrc.Text); // op.HeightBiggerDest = int.Parse(txtHeightBiggerDest.Text); // op.HeightLessSrc = int.Parse(txtHeightLessSrc.Text); // op.HeightLessDest = int.Parse(txtHeightLessDest.Text); // op.KeepAspect = chkKeepAspect.Checked; // op.AspectType = ((KeyValuePair<string, AspectType>)cmbKeepAspect.SelectedItem).Value; // op.DoAfterEdit = chkDoAfterEdit.Checked; // op.DoAfterEditPath = txtDoAfterEdit.Text; // op.Save(); Option.Save(); Close(); }
/// <summary> /// コンストラクタ。 /// </summary> public ScreenShot() { _dir = Option.Instance().SaveDirectory; _fileFmt = Option.Instance().FileNameFormat; _imgFmt = Option.Instance().ImageFormat; // 拡張子を設定する。Jpegの場合は"jpg"、それ以外は名称をそのままに小文字に変換している。 _ext = _imgFmt.Equals(ImageFormat.Jpeg) ? "jpg" : _imgFmt.ToString().ToLower(); _matches = Rx.Matches(_fileFmt); }
/// <summary> /// 画面の初期化 /// </summary> private void Initialize() { var formatList = new[] { new KeyValuePair <string, ImageFormat>(".png", ImageFormat.Png), new KeyValuePair <string, ImageFormat>(".bmp", ImageFormat.Bmp), new KeyValuePair <string, ImageFormat>(".jpg", ImageFormat.Jpeg), }; cmbImageFormat.DataSource = formatList; cmbImageFormat.DisplayMember = "Key"; cmbImageFormat.ValueMember = "Value"; //var aspectList = new[] // { // new KeyValuePair<string, AspectType>(AspectType.Width.GetName(), AspectType.Width), // new KeyValuePair<string, AspectType>(AspectType.Height.GetName(), AspectType.Height), // new KeyValuePair<string, AspectType>(AspectType.Bigger.GetName(), AspectType.Bigger), // new KeyValuePair<string, AspectType>(AspectType.Smaller.GetName(), AspectType.Smaller) // }; //cmbKeepAspect.DataSource = aspectList; //cmbKeepAspect.DisplayMember = "Key"; //cmbKeepAspect.ValueMember = "Value"; // 保存先 txtSaveDirectory.Text = Option.Instance().SaveDirectory; txtFileNameFormat.Text = Option.Instance().FileNameFormat; cmbImageFormat.SelectedValue = Option.Instance().ImageFormat; // 後処理 // chkDoAfterProcessing.Checked = op.DoAfterProcessing; // chkDoResize.Checked = op.DoResize; // txtWidthBiggerSrc.Text = op.WidthBiggerSrc.ToString(); // txtWidthBiggerDest.Text = op.WidthBiggerDest.ToString(); // txtWidthLessSrc.Text = op.WidthLessSrc.ToString(); // txtWidthLessDest.Text = op.WidthLessDest.ToString(); // txtHeightBiggerSrc.Text = op.HeightBiggerSrc.ToString(); // txtHeightBiggerDest.Text = op.HeightBiggerDest.ToString(); // txtHeightLessSrc.Text = op.HeightLessSrc.ToString(); // txtHeightLessDest.Text = op.HeightLessDest.ToString(); // chkKeepAspect.Checked = op.KeepAspect; // cmbKeepAspect.SelectedItem = op.AspectType; // chkDoAfterEdit.Checked = op.DoAfterEdit; // txtDoAfterEdit.Text = op.DoAfterEditPath; //実装していない機能を隠す grpAfter.Visible = false; btnCancel.Location = new Point(btnCancel.Location.X, 115); btnOK.Location = new Point(btnOK.Location.X, 111); Height = 181; }
/// <summary> /// 通知アイコンを登録する /// </summary> /// <param name="form">MainFormのインスタンス</param> private static void RegisterNotifyIcon(MainForm form) { // 通知アイコン設定 NotifyIcon = new NotifyIcon { Icon = new Icon("RabiShot.ico"), Visible = true }; NotifyIcon.DoubleClick += (sender, e) => { form.ShowWindow(); NotifyIcon.Visible = false; }; Application.ApplicationExit += (sender, e) => { NotifyIcon.Dispose(); }; // 右クリックメニューの登録 _menu = new ContextMenuStrip(); // ウインドウ表示 _tiShowMainWindow = new ToolStripMenuItem(); _tiShowMainWindow.Text = @"ウインドウ表示"; _tiShowMainWindow.Click += (sender, e) => { form.ShowWindow(); }; _menu.Items.Add(_tiShowMainWindow); // セパレータ _menu.Items.Add(new ToolStripSeparator()); // オプション _tiShowOption = new ToolStripMenuItem(); _tiShowOption.Text = @"オプション"; _tiShowOption.Click += (sender, e) => { form.ShowOption(); }; _menu.Items.Add(_tiShowOption); // 保存先を開く _tlOpenSaveDirectory = new ToolStripMenuItem(); _tlOpenSaveDirectory.Text = @"保存先を開く"; _tlOpenSaveDirectory.Click += (sender, e) => { Process.Start("explorer.exe", @"/n, " + Option.Instance().SaveDirectory); }; _menu.Items.Add(_tlOpenSaveDirectory); // セパレータ _menu.Items.Add(new ToolStripSeparator()); // RabiShotについて _tlShowAbout = new ToolStripMenuItem(); _tlShowAbout.Text = @"RabiShotについて"; _tlShowAbout.Click += (sender, e) => { MessageBox.Show("未実装"); }; _menu.Items.Add(_tlShowAbout); // 終了 _tlClose = new ToolStripMenuItem(); _tlClose.Text = @"終了"; _tlClose.Click += (sender, e) => { Application.Exit(); }; _menu.Items.Add(_tlClose); // アプリケーション終了処理 Application.ApplicationExit += (sender, e) => { _menu.Dispose(); _tiShowMainWindow.Dispose(); _tiShowOption.Dispose(); _tlOpenSaveDirectory.Dispose(); _tlShowAbout.Dispose(); _tlClose.Dispose(); }; NotifyIcon.ContextMenuStrip = _menu; }