Take the following steps to start a project and to add some code that updates a gauge during processing and detects a user interrupt:
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32 " folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of ImageViewer to the form. If you do not have ImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse, select Leadtools.Controls.WinForms.DLL from the "C:\LEADTOOLS 20\Bin\DotNet4\Win32" folder, click Open, and then click OK.
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Controls.WinFormsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.Core
using Leadtools;using Leadtools.Codecs;using Leadtools.Controls.WinForms;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Core;
Add an event handler to the Form1 Load event and add the following code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' load an image into our viewerDim codecs As New RasterCodecs()rasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Image3.cmp")' disable the cancel button for nowButton2.Enabled = FalseEnd Sub
private void Form1_Load(object sender, System.EventArgs e){// load an image into our viewerRasterCodecs codecs = new RasterCodecs();rasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Image3.cmp");// disable the cancel button for nowbutton2.Enabled = false;}
Double-click the "median" button on the form to add the event handler for it and add the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickcanceled = FalseProgressBar1.Value = 0' disable the median button and enable the cancel buttonButton1.Enabled = FalseButton2.Enabled = TrueDim command As New MedianCommand(40)' subscribe to the progress eventAddHandler command.Progress, AddressOf median_Progress' run the median commandcommand.Run(RasterImageViewer1.Image)' enable the median button and disable the cancel buttonButton1.Enabled = TrueButton2.Enabled = FalseProgressBar1.Value = 0End Sub
private void button1_Click(object sender, System.EventArgs e){canceled = false;progressBar1.Value = 0;// disable the median button and enable the cancel buttonbutton1.Enabled = false;button2.Enabled = true;MedianCommand command = new MedianCommand(40);// subscribe to the progress eventcommand.Progress += new EventHandler<RasterCommandProgressEventArgs>(median_Progress);// run the median commandcommand.Run(rasterImageViewer1.Image);// enable the median button and disable the cancel buttonbutton1.Enabled = true;button2.Enabled = false;progressBar1.Value = 0;}
Double-click the "cancel" button on the form to add the event handler for it and add the following code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click' Cancel the median commandcanceled = TrueEnd Sub
private void button2_Click(object sender, System.EventArgs e){// Cancel the median commandcanceled = true;}
Add the below code to the Form1 class:
Private canceled As BooleanPrivate Sub median_Progress(ByVal sender As System.Object, ByVal e As RasterCommandProgressEventArgs)' update the value of the progress barProgressBar1.Value = e.Percent' determine whether the cancel button has been pressedIf (canceled) Thene.Cancel = TrueEnd IfApplication.DoEvents()End Sub
private bool canceled;private void median_Progress(object sender, RasterCommandProgressEventArgs e){// update the value of the progress barprogressBar1.Value = e.Percent;// determine whether the cancel button has been pressedif(canceled)e.Cancel = true;Application.DoEvents();}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
