SysTray() { InitializeComponent(); CreateHandle(); Icon = AssemblyRoutines.GetAppIcon(); Service.StateChanged += delegate { this.Invoke(() => { StartStop.Checked = Service.Running; string title = "Cistera Screen Capture"; if (Service.Running) { notifyIcon.Icon = Icon; title += " started"; } else { //notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetGreyScale(Icon.ToBitmap()).GetHicon()); notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetInverted(Icon.ToBitmap()).GetHicon()); title += " stopped"; } notifyIcon.Text = title; }); }; }
public SettingsForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + ": Settings"; load_settings(); }
//static public void OpenDialog() //{ // if (SettingsForm.This.Visible) // SettingsForm.This.Activate(); // else // SettingsForm.This.ShowDialog(); //} //public static SettingsForm This //{ // get // { // if (_This == null || _This.IsDisposed) // _This = new SettingsForm(); // return _This; // } //} //static SettingsForm _This = null; public SettingsForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Application.ProductName; //important.Text = "Important! Letting folder '" + Config.StorageDir + "' be synchronized by a remote drive application may bring to malfunction."; load_settings(); }
public AboutBox() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); this.Text = String.Format("About {0}", AssemblyTitle); this.labelProductName.Text = AssemblyProduct; this.labelVersion.Text = "Version: " + Program.Version;// AssemblyRoutines.GetAssemblyCompiledTime(Assembly.GetEntryAssembly()).ToString("yyMMdd-HHmmss"); //String.Format("Version {0}", AssemblyVersion); this.labelCopyright.Text = AssemblyCopyright; this.labelCompanyName.Text = AssemblyCompany; this.textBoxDescription.Text = AssemblyDescription; }
public TextForm(string caption, string t, bool html) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = AboutBox.AssemblyProduct + ": " + caption;// Application.ProductName; if (html) { browser.DocumentText = t; browser.BringToFront(); } else { textBox.Text = t; textBox.BringToFront(); } }
public FileFilterForm(string folder, Regex r) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = "Filtered Files"; files.ReadOnly = true; Load += delegate { foreach (string f in FileSystemRoutines.GetFiles(folder)) { int i = files.Items.Add(f); if (r.IsMatch(f)) { files.SelectedIndex = i; } } }; }
public Template2Form(Template2 t) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Application.ProductName + ": additional properties of '" + t.Template.Name + "'"; template2 = t; Active.Checked = t.Active; Comment.Text = t.Comment; OrderWeight.Value = (decimal)t.OrderWeight; if (t.FileFilterRegex != null) { FileFilterRegex.Text = Serialization.Json.Serialize(t.FileFilterRegex, false); } else { FileFilterRegex.Text = ""; } }
SysTray() { InitializeComponent(); CreateHandle(); Load += delegate { Icon = AssemblyRoutines.GetAppIcon(); ServiceStateChanged(UiApiClient.GetServiceStatus()); silentlyToolStripMenuItem.Checked = !Settings.View.DisplayNotifications; //string __file; //Cliver.CisteraScreenCaptureService.Settings.GeneralSettings general = UiApiClient.GetServiceSettings(out __file); //if(general.CapturedMonitorRectangle == null) //{ // if(string.IsNullOrWhiteSpace( general.CapturedMonitorDeviceName)) // general.CapturedMonitorDeviceName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName(); // if (string.IsNullOrWhiteSpace(general.CapturedMonitorDeviceName)) // LogMessage.Error("Could not detect default monitor."); // else // { // WinApi.User32.RECT? a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName); // if (a == null) // { // string defaultMonitorName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName(); // LogMessage.Warning("Monitor '" + general.CapturedMonitorDeviceName + "' was not found. Using default one '" + defaultMonitorName + "'"); // general.CapturedMonitorDeviceName = defaultMonitorName; // a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName); // if (a == null) // LogMessage.Error("Monitor '" + general.CapturedMonitorDeviceName + "' was not found."); // } // general.CapturedMonitorRectangle = a; // } // general.Save(__file); //} }; }
public TemplateForm(TemplateManager templateManager) { InitializeComponent(); Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + ": Template Editor"; this.templateManager = templateManager; initializeAnchorsTable(); initializeConditionsTable(); initializeFieldsTable(); picture.MouseDown += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); ResizebleBox rb = findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide); if (rb != null) { drawingMode = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? DrawingModes.resizingSelectionBoxV : DrawingModes.resizingSelectionBoxH; Cursor.Current = drawingMode == DrawingModes.resizingSelectionBoxV ? Cursors.VSplit : Cursors.HSplit; selectionBoxPoint0 = rb.R.Location; selectionBoxPoint1 = rb.R.Location; selectionBoxPoint2 = new Point(rb.R.Right, rb.R.Bottom); } else { drawingMode = DrawingModes.drawingSelectionBox; selectionBoxPoint0 = p; selectionBoxPoint1 = p; selectionBoxPoint2 = p; } selectionCoordinates.Text = selectionBoxPoint1.ToString(); }; picture.MouseMove += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); switch (drawingMode) { case DrawingModes.NULL: selectionCoordinates.Text = p.ToString(); if (findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide) != null) { Cursor.Current = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? Cursors.VSplit : Cursors.HSplit; } else { Cursor.Current = Cursors.Default; } return; case DrawingModes.drawingSelectionBox: if (selectionBoxPoint0.X < p.X) { selectionBoxPoint1.X = selectionBoxPoint0.X; selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; selectionBoxPoint2.X = selectionBoxPoint0.X; } if (selectionBoxPoint0.Y < p.Y) { selectionBoxPoint1.Y = selectionBoxPoint0.Y; selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; selectionBoxPoint2.Y = selectionBoxPoint0.Y; } break; case DrawingModes.resizingSelectionBoxV: if (Math.Abs(selectionBoxPoint2.X - p.X) < Math.Abs(p.X - selectionBoxPoint1.X)) { selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; } break; case DrawingModes.resizingSelectionBoxH: if (Math.Abs(selectionBoxPoint2.Y - p.Y) < Math.Abs(p.Y - selectionBoxPoint1.Y)) { selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; } break; } selectionCoordinates.Text = selectionBoxPoint1.ToString() + ":" + selectionBoxPoint2.ToString(); RectangleF r = new RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); clearImageFromBoxes(); drawBoxes(Settings.Appearance.SelectionBoxColor, Settings.Appearance.SelectionBoxBorderWidth, new List <System.Drawing.RectangleF> { r }); }; picture.MouseUp += delegate(object sender, MouseEventArgs e) { try { if (pages == null) { return; } if (drawingMode == DrawingModes.NULL) { return; } drawingMode = DrawingModes.NULL; Template.RectangleF r = new Template.RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); if (r.Width == 0 || r.Y == 0)//accidental tap { return; } switch (settingMode) { case SettingModes.SetAnchor: { if (currentAnchorControl == null) { break; } currentAnchorControl.SetTagFromControl(); Template.Anchor a = (Template.Anchor)currentAnchorControl.Row.Tag; a.Position = new Template.PointF { X = r.X, Y = r.Y }; try { switch (a.Type) { case Template.Anchor.Types.PdfText: { Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a; pt.CharBoxs = new List <Template.Anchor.PdfText.CharBox>(); List <Pdf.Line> lines = Pdf.RemoveDuplicatesAndGetLines(Pdf.GetCharBoxsSurroundedByRectangle(pages[currentPageI].PdfCharBoxs, r.GetSystemRectangleF(), true), null); foreach (Pdf.Line l in lines) { foreach (Pdf.CharBox cb in l.CharBoxs) { pt.CharBoxs.Add(new Template.Anchor.PdfText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } pt.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.OcrText: { Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a; ot.CharBoxs = new List <Template.Anchor.OcrText.CharBox>(); var selectedOcrCharBoxs = new List <Ocr.CharBox>(); if (ot.OcrEntirePage) { selectedOcrCharBoxs.AddRange(Ocr.GetCharBoxsSurroundedByRectangle(pages[currentPageI].ActiveTemplateOcrCharBoxs, r.GetSystemRectangleF())); } else { foreach (Ocr.CharBox cb in Ocr.This.GetCharBoxs(pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio))) { cb.R.X += r.X; cb.R.Y += r.Y; selectedOcrCharBoxs.Add(cb); } } foreach (Ocr.Line l in Ocr.GetLines(selectedOcrCharBoxs, null)) { foreach (Ocr.CharBox cb in l.CharBoxs) { ot.CharBoxs.Add(new Template.Anchor.OcrText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } ot.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.ImageData: { Template.Anchor.ImageData id = (Template.Anchor.ImageData)a; using (Bitmap rb = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio)) { using (Bitmap b = ImageData.GetScaled(rb, Settings.Constants.Image2PdfResolutionRatio)) id.Image = new ImageData(b, false); } } break; default: throw new Exception("Unknown option: " + a.Type); } setAnchorRow(currentAnchorControl.Row, a); clearImageFromBoxes(); findAndDrawAnchor(a.Id); } finally { anchors.EndEdit(); } } break; case SettingModes.SetField: { if (fields.SelectedRows.Count < 1) { break; } var row = fields.SelectedRows[0]; Template.Field f = (Template.Field)row.Tag; f.Rectangle = r; if (f.LeftAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.LeftAnchor.Id); f.LeftAnchor.Shift = aai.Shift.Width; } if (f.TopAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.TopAnchor.Id); f.TopAnchor.Shift = aai.Shift.Height; } if (f.RightAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.RightAnchor.Id); f.RightAnchor.Shift = aai.Shift.Width; } if (f.BottomAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.BottomAnchor.Id); f.BottomAnchor.Shift = aai.Shift.Height; } setFieldRow(row, f); extractFieldAndDrawSelectionBox(f); //owners2resizebleBox[f] = new ResizebleBox(f, f.Rectangle.GetSystemRectangleF(), Settings.Appearance.SelectionBoxBorderWidth); } break; case SettingModes.NULL: break; default: throw new Exception("Unknown option: " + settingMode); } } catch (Exception ex) { Message.Error2(ex); } }; Shown += delegate { Application.DoEvents();//make form be drawn completely setUIFromTemplate(templateManager.Template); }; FormClosed += delegate { if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } templateManager.LastTestFile = testFile.Text; }; this.EnumControls((Control c) => { if (c is SplitContainer s) { s.BackColor = Color.FromArgb(80, 70, 0); s.SplitterWidth = 2; s.Panel1.BackColor = SystemColors.Control; s.Panel2.BackColor = SystemColors.Control; } }, true); testFile.TextChanged += delegate { try { if (picture.Image != null) { picture.Image.Dispose(); picture.Image = null; } if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } if (string.IsNullOrWhiteSpace(testFile.Text)) { return; } testFile.SelectionStart = testFile.Text.Length; testFile.ScrollToCaret(); if (!File.Exists(testFile.Text)) { Log.Message.Error("File '" + testFile.Text + "' does not exist!"); return; } pages = new PageCollection(testFile.Text); totalPageNumber = pages.PdfReader.NumberOfPages; lTotalPages.Text = " / " + totalPageNumber; showPage(1); } catch (Exception ex) { Log.Message.Error(ex); } }; pictureScale.ValueChanged += delegate { if (!loadingTemplate) { setScaledImage(); } }; pageRotation.SelectedIndexChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; autoDeskew.CheckedChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; Load += delegate { }; save.Click += Save_Click; cancel.Click += delegate { Close(); }; Help.LinkClicked += Help_LinkClicked; Configure.LinkClicked += Configure_LinkClicked; About.LinkClicked += About_LinkClicked; bTestFile.Click += delegate(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); if (!string.IsNullOrWhiteSpace(testFile.Text)) { d.InitialDirectory = PathRoutines.GetDirFromPath(testFile.Text); } else if (!string.IsNullOrWhiteSpace(templateManager.TestFileDefaultFolder)) { d.InitialDirectory = templateManager.TestFileDefaultFolder; } d.Filter = "PDF|*.pdf|" + "All files (*.*)|*.*"; if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } testFile.Text = d.FileName; }; ShowPdfText.LinkClicked += ShowPdfText_LinkClicked; ShowOcrText.LinkClicked += ShowOcrText_LinkClicked; ShowAsJson.LinkClicked += showAsJson_LinkClicked; tCurrentPage.Leave += delegate { changeCurrentPage(); }; tCurrentPage.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { changeCurrentPage(); } }; }
public MainForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + " [" + Program.Version + "] / " + PdfDocumentParser.Program.Name + " [" + PdfDocumentParser.Program.Version.ToString(2) + "]"; Message.Owner = this; InputFolder.Text = Settings.General.InputFolder; LoadTemplates(); Active.ValueType = typeof(bool); Selected.ValueType = typeof(bool); OrderWeight.ValueType = typeof(float); FileFilterRegex.ValueType = typeof(Regex); Settings.Template2s.TouchedChanged += delegate { this.BeginInvoke(() => { saveTemplates.Enabled = Settings.Template2s.IsTouched(); }); }; saveTemplates.Enabled = false; saveTemplates.Click += delegate { saveTemplatesFromTableIfTouched(false); }; FormClosing += delegate(object sender, FormClosingEventArgs e) { Settings.TemplateLocalInfo.Clear_Save(); if (!saveTemplatesFromTableIfTouched(true)) { e.Cancel = true; } }; template2s.CellValidating += delegate(object sender, DataGridViewCellValidatingEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; switch (template2s.Columns[e.ColumnIndex].Name) { case "Name_": { if (string.IsNullOrWhiteSpace((string)e.FormattedValue)) { if (t != null) { throw new Exception("Name cannot be empty!"); } return; } string name2 = ((string)e.FormattedValue).Trim(); foreach (DataGridViewRow rr in template2s.Rows) { if (rr.Index != e.RowIndex && name2 == (string)rr.Cells["Name_"].Value) { throw new Exception("Name '" + name2 + "' is duplicated!"); } } if ((string)r.Cells["Name_"].Value != name2) { r.Cells["Name_"].Value = name2; } } return; } } catch (Exception ex) { e.Cancel = true; Message.Error2(ex); } }; template2s.DataError += delegate(object sender, DataGridViewDataErrorEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; switch (template2s.Columns[e.ColumnIndex].Name) { case "OrderWeight": throw new Exception("Order must be a float number:\r\n" + e.Exception.Message); case "FileFilterRegex": throw new Exception("FileFilterRegex must be a regex."); } } catch (Exception ex) { Message.Error2(ex); } }; template2s.CellValueChanged += delegate(object sender, DataGridViewCellEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; if (t == null) { return; } if (e.ColumnIndex < 0)//row's header { return; } switch (template2s.Columns[e.ColumnIndex].Name) { case "Name_": t.Template.Name = (string)r.Cells["Name_"].Value; Settings.Template2s.Touch(); return; case "Active": t.Active = (bool)r.Cells["Active"].Value; Settings.Template2s.Touch(); return; case "Comment": t.Comment = (string)r.Cells["Comment"].Value; Settings.Template2s.Touch(); return; case "OrderWeight": t.OrderWeight = (float)r.Cells["OrderWeight"].Value; Settings.Template2s.Touch(); return; case "FileFilterRegex": t.FileFilterRegex = (Regex)r.Cells["FileFilterRegex"].Value; Settings.Template2s.Touch(); return; return; } } catch (Exception ex) { Message.Error2(ex); } }; template2s.UserDeletingRow += delegate(object sender, DataGridViewRowCancelEventArgs e) { try { if (e.Row == null || e.Row.Tag == null) { return; } if (!Message.YesNo("Template '" + e.Row.Cells["Name_"].Value + "' will be deleted! Proceed?")) { e.Cancel = true; return; } } catch (Exception ex) { Log.Message.Error(ex); } }; template2s.UserDeletedRow += delegate(object sender, DataGridViewRowEventArgs e) { Settings.Template2s.Touch(); }; TemplateManager.Templates = template2s; template2s.SelectionChanged += delegate(object sender, EventArgs e) { //if (templates.SelectedRows.Count < 1) // return; //var r = templates.SelectedRows[templates.SelectedRows.Count - 1]; //if (r.IsNewRow)//hacky forcing commit a newly added row and display the blank row //{ // try // { // int i = templates.Rows.Add(); // templates.Rows[i].Selected = true; // templates.Rows[i].Cells["Active"].Value = true; // } // catch { } //} }; template2s.CellClick += delegate(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } DataGridViewRow r = template2s.Rows[e.RowIndex]; if (e.ColumnIndex < 0)//row's header { return; } if (r.IsNewRow)//hacky forcing commit a newly added row and display the blank row { try { int i = template2s.Rows.Add(); r = template2s.Rows[i]; Template2 t = Settings.Template2s.CreateInitialTemplate(); r.Tag = t; r.Cells["Active"].Value = t.Active; r.Cells["OrderWeight"].Value = t.OrderWeight; r.Cells["FileFilterRegex"].Value = t.FileFilterRegex; r.Selected = true; } catch { } } switch (template2s.Columns[e.ColumnIndex].Name) { case "Edit": editTemplate(r); break; case "Copy": Template2 t = (Template2)r.Tag; if (t == null) { return; } Template2 t2 = Serialization.Json.Deserialize <Template2>(Serialization.Json.Serialize(t)); t2.Template.Name = ""; t2.Template.Editor.TestFile = null; int i = template2s.Rows.Add(new DataGridViewRow()); DataGridViewRow r2 = template2s.Rows[i]; r2.Tag = t2; r2.Cells["Name_"].Value = t2.Template.Name.Trim(); r2.Cells["Active"].Value = t2.Active; r2.Cells["OrderWeight"].Value = t2.OrderWeight; r2.Cells["FileFilterRegex"].Value = t2.FileFilterRegex; editTemplate(r2); break; case "Edit2": edit2Template(r); break; } }; progress.Maximum = 10000; }