Add snipping tool
This commit is contained in:
parent
a065c4c699
commit
dbaa8b111a
@ -32,6 +32,9 @@ public class RibbonController : ExcelRibbon
|
|||||||
<group id='exportTab' label='Экспорт'>
|
<group id='exportTab' label='Экспорт'>
|
||||||
<button id='dxfexport' getEnabled='GetDxfEnabled' label='DXF' size='large' image='DXF' onAction='OnToolPressed'/>
|
<button id='dxfexport' getEnabled='GetDxfEnabled' label='DXF' size='large' image='DXF' onAction='OnToolPressed'/>
|
||||||
</group>
|
</group>
|
||||||
|
<group id='importTab' label='OCR'>
|
||||||
|
<button id='ocr' label='Распознать таблицу' size='large' imageMso='TableInsert' onAction='OnToolPressed'/>
|
||||||
|
</group>
|
||||||
<group id='settings' getLabel='GetVersionLabel'>
|
<group id='settings' getLabel='GetVersionLabel'>
|
||||||
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' image='RhSolutions' onAction='OnSetPricePressed'/>
|
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' image='RhSolutions' onAction='OnSetPricePressed'/>
|
||||||
</group>
|
</group>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
|
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
|
||||||
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
|
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
|
||||||
<Reference Path="System.ValueTuple.dll" Pack="true" />
|
<Reference Path="System.ValueTuple.dll" Pack="true" />
|
||||||
|
<Reference Path="SnippingTool.dll" Pack="true" />
|
||||||
<Image Name='RhSolutions' Path='Images\RhSolutions.png' Pack='true' />
|
<Image Name='RhSolutions' Path='Images\RhSolutions.png' Pack='true' />
|
||||||
<Image Name='DXF' Path='Images\DXF.png' Pack='true' />
|
<Image Name='DXF' Path='Images\DXF.png' Pack='true' />
|
||||||
<Image Name='Sleeve' Path='Images\Sleeve.png' Pack='true' />
|
<Image Name='Sleeve' Path='Images\Sleeve.png' Pack='true' />
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
||||||
|
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Images\Coupling.png">
|
<None Update="Images\Coupling.png">
|
||||||
|
22
RhSolutions.AddIn/Tools/OcrTool.cs
Normal file
22
RhSolutions.AddIn/Tools/OcrTool.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#if !NET472
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
|
internal class OcrTool : Tool
|
||||||
|
{
|
||||||
|
public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Execute()
|
||||||
|
{
|
||||||
|
var bmp = SnippingTool.SnippingTool.Snip();
|
||||||
|
if (bmp != null)
|
||||||
|
{
|
||||||
|
// Do something with the bitmap
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ internal class ToolFactory
|
|||||||
"guess" => new GuessTool(readerFactory, writerFactory),
|
"guess" => new GuessTool(readerFactory, writerFactory),
|
||||||
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
|
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
|
||||||
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
|
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
|
||||||
|
"ocr" => new OcrTool(readerFactory, writerFactory),
|
||||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||||
};
|
};
|
||||||
return tool;
|
return tool;
|
||||||
|
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RhSolutions.Tests", "RhSolu
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "RhSolutions.ProductSku\RhSolutions.ProductSku.csproj", "{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "RhSolutions.ProductSku\RhSolutions.ProductSku.csproj", "{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -27,6 +29,10 @@ Global
|
|||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{59CD05D0-71E0-4027-968A-8BE89A6FDCEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
38
SnippingTool/SnippingTool.Designer.cs
generated
Normal file
38
SnippingTool/SnippingTool.Designer.cs
generated
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
namespace SnippingTool;
|
||||||
|
|
||||||
|
partial class SnippingTool
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
this.Text = "Form1";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
86
SnippingTool/SnippingTool.cs
Normal file
86
SnippingTool/SnippingTool.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
namespace SnippingTool;
|
||||||
|
|
||||||
|
public partial class SnippingTool : Form
|
||||||
|
{
|
||||||
|
public static Image? Snip()
|
||||||
|
{
|
||||||
|
var rc = Screen.PrimaryScreen.Bounds;
|
||||||
|
using Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
||||||
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
gr.CopyFromScreen(0, 0, 0, 0, bmp.Size);
|
||||||
|
using var snipper = new SnippingTool(bmp);
|
||||||
|
|
||||||
|
return snipper.ShowDialog() == DialogResult.OK ? snipper.Image : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SnippingTool(Image screenShot)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BackgroundImage = screenShot;
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
|
WindowState = FormWindowState.Maximized;
|
||||||
|
DoubleBuffered = true;
|
||||||
|
}
|
||||||
|
public Image? Image { get; set; }
|
||||||
|
|
||||||
|
private Rectangle rcSelect = new Rectangle();
|
||||||
|
private Point pntStart;
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button != MouseButtons.Left)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pntStart = e.Location;
|
||||||
|
rcSelect = new Rectangle(e.Location, new Size(0, 0));
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button != MouseButtons.Left)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int x1 = Math.Min(e.X, pntStart.X);
|
||||||
|
int y1 = Math.Min(e.Y, pntStart.Y);
|
||||||
|
int x2 = Math.Max(e.X, pntStart.X);
|
||||||
|
int y2 = Math.Max(e.Y, pntStart.Y);
|
||||||
|
rcSelect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (rcSelect.Width <= 0 || rcSelect.Height <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Image = new Bitmap(rcSelect.Width, rcSelect.Height);
|
||||||
|
using Graphics gr = Graphics.FromImage(Image);
|
||||||
|
gr.DrawImage(BackgroundImage, new Rectangle(0, 0, Image.Width, Image.Height),
|
||||||
|
rcSelect, GraphicsUnit.Pixel);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
using Brush br = new SolidBrush(Color.FromArgb(120, Color.White));
|
||||||
|
int x1 = rcSelect.X; int x2 = rcSelect.X + rcSelect.Width;
|
||||||
|
int y1 = rcSelect.Y; int y2 = rcSelect.Y + rcSelect.Height;
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(0, 0, x1, Height));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x2, 0, Width - x2, Height));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x1, 0, x2 - x1, y1));
|
||||||
|
e.Graphics.FillRectangle(br, new Rectangle(x1, y2, x2 - x1, Height - y2));
|
||||||
|
|
||||||
|
using Pen pen = new Pen(Color.Red, 3);
|
||||||
|
e.Graphics.DrawRectangle(pen, rcSelect);
|
||||||
|
}
|
||||||
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||||
|
{
|
||||||
|
if (keyData == Keys.Escape)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
}
|
||||||
|
return base.ProcessCmdKey(ref msg, keyData);
|
||||||
|
}
|
||||||
|
}
|
12
SnippingTool/SnippingTool.csproj
Normal file
12
SnippingTool/SnippingTool.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<LangVersion>10</LangVersion>
|
||||||
|
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user