diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-07 23:05:19 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-07 23:05:19 +0300 |
commit | 1511dafa934738a6baff1288c95daaa087c21d5f (patch) | |
tree | acd63e59c44db7b4e67bf25449efef512637585a | |
parent | dbaa8b111a5d869159db7e58b14c026806265874 (diff) |
Hide application window on OcrTool press
-rw-r--r-- | RhSolutions.AddIn/Tools/OcrTool.cs | 22 | ||||
-rw-r--r-- | RhSolutions.AddIn/Tools/ToolFactory.cs | 3 |
2 files changed, 19 insertions, 6 deletions
diff --git a/RhSolutions.AddIn/Tools/OcrTool.cs b/RhSolutions.AddIn/Tools/OcrTool.cs index 4e0f828..965158b 100644 --- a/RhSolutions.AddIn/Tools/OcrTool.cs +++ b/RhSolutions.AddIn/Tools/OcrTool.cs @@ -2,21 +2,33 @@ using System.Runtime.Versioning; #endif +using System.Threading.Tasks; + namespace RhSolutions.Tools; internal class OcrTool : Tool { - public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory) - { - } + public Application Application { get; set; } + public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application) : base(readerFactory, writerFactory) + { + Application = application; + } - public override void Execute() - { + public override void Execute() + { + Application.Visible = false; + Task.Run(async delegate + { + await Task.Delay(100); + }).Wait(); + var bmp = SnippingTool.SnippingTool.Snip(); if (bmp != null) { // Do something with the bitmap //... } + + Application.Visible = true; } }
\ No newline at end of file diff --git a/RhSolutions.AddIn/Tools/ToolFactory.cs b/RhSolutions.AddIn/Tools/ToolFactory.cs index e65ab0c..045e893 100644 --- a/RhSolutions.AddIn/Tools/ToolFactory.cs +++ b/RhSolutions.AddIn/Tools/ToolFactory.cs @@ -5,6 +5,7 @@ internal class ToolFactory static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService<ReaderFactory>(); static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>(); static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>(); + static Application application = RhSolutionsAddIn.ServiceProvider.GetService<Application>(); public Tool GetTool(string toolName) { @@ -17,7 +18,7 @@ internal class ToolFactory "guess" => new GuessTool(readerFactory, writerFactory), "fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"), "fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"), - "ocr" => new OcrTool(readerFactory, writerFactory), + "ocr" => new OcrTool(readerFactory, writerFactory, application), _ => throw new Exception($"Неизвестный инструмент {toolName}"), }; return tool; |