Take the following steps to create and run a program that shows how to add data binding to a ImageViewer control. Note: You should first create a database file using MS Access that has at least one table, and the table name should be "Example". This table should include at least one column using the "Image" name and the "OLE Object" data type.
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 Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32" folder and select the following DLLs:
Click Select and then click OK to add the above DLLs to the application.
Drag an OleDbDataAdapter control from the Data group in the Toolbox and drop it on Form1. When the Data Adapter Configuration Wizard dialog appears, perform the following steps:
In the design view right-click on oleDbDataAdapter1 and click on Generate DataSet... menu item.
Property | Value |
DataSource | dataSet11 |
DataMember | Example |
Property | Value |
BindingSource | bindingSource1 |
Property | Value |
Name | _pnlControls |
Dock | Left |
Property | Value |
Name | _btnLoad |
Text | Load |
Property | Value |
Name | _btnSubmit |
Text | Submit |
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 Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Controls.WinForms
Imports Leadtools.WinForms.CommonDialogs.File
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls.WinForms;
using Leadtools.WinForms.CommonDialogs.File;
Add the following private variables to the Form1 class:
private _viewer As ImageViewer
private _codecs As RasterCodecs
private ImageViewer _viewer;
private RasterCodecs _codecs;
Add an event handler to the Form1 Load event and add the following code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
oleDbDataAdapter1.Fill(dataSet11)
' Initialize a new RasterCodecs object
_codecs = New RasterCodecs()
_viewer = New ImageViewer()
_viewer.BackColor = Color.Bisque
_viewer.Dock = DockStyle.Fill
Controls.Add(_viewer)
_viewer.BringToFront()
_viewer.DataBindings.Add(New System.Windows.Forms.Binding("BindingData", bindingSource1, "Image", True))
End Sub
private void Form1_Load(object sender, EventArgs e)
{
oleDbDataAdapter1.Fill(dataSet11);
// Initialize a new RasterCodecs object
_codecs = new RasterCodecs();
_viewer = new ImageViewer();
_viewer.BackColor = Color.Bisque;
_viewer.Dock = DockStyle.Fill;
Controls.Add(_viewer);
_viewer.BringToFront();
_viewer.DataBindings.Add(new System.Windows.Forms.Binding("BindingData",
bindingSource1,
"Image",
true));
}
Add the following code to the Form1 class:
Private Sub _btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ofd As RasterOpenDialog = New RasterOpenDialog(_codecs)
ofd.DereferenceLinks = True
ofd.CheckFileExists = False
ofd.CheckPathExists = True
ofd.EnableSizing = False
ofd.LoadFileImage = False
ofd.LoadOptions = False
ofd.LoadRotated = False
ofd.LoadCompressed = False
ofd.Multiselect = False
ofd.ShowGeneralOptions = False
ofd.ShowLoadCompressed = False
ofd.ShowLoadOptions = False
ofd.ShowLoadRotated = False
ofd.ShowMultipage = False
ofd.ShowPreview = True
ofd.ShowProgressive = False
ofd.ShowRasterOptions = False
ofd.ShowTotalPages = False
ofd.ShowDeletePage = False
ofd.ShowFileInformation = True
ofd.UseFileStamptoPreview = False
ofd.PreviewWindowVisible = True
ofd.Title = "LEADTOOLS Open Dialog"
If ofd.ShowDialog(Me) = DialogResult.OK Then
_viewer.Image = _codecs.Load(ofd.OpenedFileData(0).Name, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
End If
End Sub
private void _btnLoad_Click(object sender, EventArgs e)
{
RasterOpenDialog ofd = new RasterOpenDialog(_codecs);
ofd.DereferenceLinks = true;
ofd.CheckFileExists = false;
ofd.CheckPathExists = true;
ofd.EnableSizing = false;
ofd.LoadFileImage = false;
ofd.LoadOptions = false;
ofd.LoadRotated = false;
ofd.LoadCompressed = false;
ofd.Multiselect = false;
ofd.ShowGeneralOptions = false;
ofd.ShowLoadCompressed = false;
ofd.ShowLoadOptions = false;
ofd.ShowLoadRotated = false;
ofd.ShowMultipage = false;
ofd.ShowPreview = true;
ofd.ShowProgressive = false;
ofd.ShowRasterOptions = false;
ofd.ShowTotalPages = false;
ofd.ShowDeletePage = false;
ofd.ShowFileInformation = true;
ofd.UseFileStamptoPreview = false;
ofd.PreviewWindowVisible = true;
ofd.Title = "LEADTOOLS Open Dialog";
if (ofd.ShowDialog(this) == DialogResult.OK)
{
_viewer.Image = _codecs.Load(ofd.OpenedFileData[0].Name,
0,
CodecsLoadByteOrder.BgrOrGray,
1,
1);
}
}
Add the following code to the Form1 class:
Private Sub _btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
bindingSource1.EndEdit()
oleDbDataAdapter1.Update(dataSet11)
End Sub
private void _btnSubmit_Click(object sender, EventArgs e)
{
bindingSource1.EndEdit();
oleDbDataAdapter1.Update(dataSet11);
}
Build, and Run the program to test it.
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET