Hide application window on OcrTool press

This commit is contained in:
Serghei Cebotari 2024-11-07 23:05:19 +03:00
parent dbaa8b111a
commit 1511dafa93
2 changed files with 19 additions and 6 deletions

View File

@ -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()
{
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;
}
}

View File

@ -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;