Using the WebImageViewer control on the server side

Show in webframe

Perform the following steps to create a project that uses the features of the LEADTOOLS WebImageViewer Control from the server side:

  1. Start Visual Studio 2005.

  2. Choose File->New->Web Site… from the menu.

  3. In the New Web Site dialog box, choose "ASP.NET Web Site" in the Templates List, and choose either "Visual C#" or "Visual Basic" in the Language drop-down list box.

  4. In the Location drop-down list box choose "File System". Enter “C:\Inetpub\wwwroot\UsingImageViewer_Server” into the Project Name field, and then click OK.

    If desired, type a new location for your project or select a directory by clicking Browse, and then click OK.

  5. In the Solution Explorer pane, right-click on the project node, and select "Add Reference…" from the context menu. In the Add Reference dialog box, click the .NET tab and select "System.Windows.Forms". Click OK to close the Add Reference dialog box.

  6. Repeat the previous step but this time in the Add Reference dialog box select the Browse tab. Browse to the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32" folder and select the following DLL:

    • Leadtools.Web.dll.

    Now click OK to close the Add Reference dialog box.

  7. In the Solution Explorer pane right-click on the "Default.aspx" file and choose the View Designer from the context menu.

  8. Go to the toolbox (View->Toolbox) and drag and drop an instance of the WebImageImageViewer onto the web form. If you do not have the WebImageViewer in your toolbox, select "Tools->Choose Toolbox Items..." from the menu. Click Browse and then select "Leadtools.Web.dll" from the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32" folder and then click Open and then click OK.

  9. Go to the toolbox (View-Toolbox) and from the Standard tab drag and drop 7 Labels, 4 Text Boxes, 4 drop-down list boxes, and 3 Buttons onto the web form.

  10. Change the properties of the dropped controls as follows:

    Control Property New Value
    Label1 IDText _lblImageUrlImage Url
    TextBox1 ID _tbImageUrl
    Label2 IDText _lblImageWidthImage Width
    TextBox2 ID _tbImageWidth
    Label3 IDText _lblImageHeightImage Height
    TextBox3 ID _tbImageHeight
    Button1 IDText _btnGetImageSizeGet Image Size
    Button2 IDText _btnViewImageView Image
    Label4 IDText _lblSizeModeSizeMode
    DropDownList1 IDAutoPostBack _ddlSizeModeTrue
    Label5 IDText _lblScaleFactorScaleFactor
    DropDownList2 IDAutoPostBack _ddlScaleFactorTrue
    Label6 IDText _lblHorizontalAlignModeHorizontalAlignMode
    DropDownList3 IDAutoPostBack _ddlHorizontalAlignModeTrue
    Label7 IDText _lblVerticalAlignModeVerticalAlignMode
    DropDownList4 IDAutoPostBack _ddlVerticalAlignModeTrue
    Button3 IDText _btnGetRealScaleFactorsGet Real Scale Factors
    TextBox4 ID _tbRealScaleFactors
  11. Switch to the "Default.aspx" code view (right-click default.aspx in the Solution Explorer, then select View Code), and add the following lines at the beginning of the file:

    Visual Basic


    Switch to the "Default.aspx" code view (right-click default.aspx in the Solution Explorer, then select View Code), and add the following lines at the beginning of the file:
    Visual Basic Imports System.Windows.Forms Imports System.Web.Hosting Imports System.Xml Imports System.Drawing Imports System.IO Imports Leadtools.Web.Controls Imports Leadtools.Web.Handlers
    C# using System.Windows.Forms; using System.Web.Hosting; using System.Xml; using System.IO; using System.Drawing; using Leadtools.Web.Controls; using Leadtools.Web.Handlers;

    C#


    Switch to the "Default.aspx" code view (right-click default.aspx in the Solution Explorer, then select View Code), and add the following lines at the beginning of the file:
    Visual Basic

    Switch to the "Default.aspx" code view (right-click default.aspx in the Solution Explorer, then select View Code), and add the following lines at the beginning of the file:
    Visual Basic Imports System.Windows.Forms Imports System.Web.Hosting Imports System.Xml Imports System.Drawing Imports System.IO Imports Leadtools.Web.Controls Imports Leadtools.Web.Handlers
    C# using System.Windows.Forms; using System.Web.Hosting; using System.Xml; using System.IO; using System.Drawing; using Leadtools.Web.Controls; using Leadtools.Web.Handlers;

    C# using System.Windows.Forms; using System.Web.Hosting; using System.Xml; using System.IO; using System.Drawing; using Leadtools.Web.Controls; using Leadtools.Web.Handlers;
  12. Update the Page_Load event handler to be as follows:

    Visual Basic


    Update the Page_Load event handler to be as follows:
    Visual Basic Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not IsPostBack) Then ' Initialize the WebImageViewer control. ImageViewer1.ResourcesPath = "Resources" ImageViewer1.ScrollBarSize = SystemInformation.VerticalScrollBarWidth ' Fill in the Combo Boxes BindDropDownListToEnum(_ddlSizeMode, GetType(ImageViewerSizeMode), ImageViewer1.SizeMode) BindDropDownListToEnum(_ddlHorizontalAlignMode, GetType(ImageViewerAlignMode), ImageViewer1.HorizontalAlignMode) BindDropDownListToEnum(_ddlVerticalAlignMode, GetType(ImageViewerAlignMode), ImageViewer1.VerticalAlignMode) Dim scaleFactors() As Integer = {1000, 800, 600, 400, 200, 100, 75, 50, 25, 10} Dim factor1 As Integer = CInt(ImageViewer1.ScaleFactor) For i As Integer = 0 To scaleFactors.Length - 1 _ddlScaleFactor.Items.Add(scaleFactors(i).ToString()) If (factor1 = scaleFactors(i)) Then _ddlScaleFactor.SelectedIndex = i End If Next End If End Sub
    C# protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { // Initialize the WebImageViewer control. ImageViewer1.ResourcesPath = "Resources"; ImageViewer1.ScrollBarSize = SystemInformation.VerticalScrollBarWidth; // Fill in the Drop-down list boxes BindDropDownListToEnum(_ddlSizeMode, typeof(ImageViewerSizeMode), ImageViewer1.SizeMode); BindDropDownListToEnum(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.HorizontalAlignMode); BindDropDownListToEnum(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.VerticalAlignMode); int[] scaleFactors = { 1000, 800, 600, 400, 200, 100, 75, 50, 25, 10 }; int factor1 = (int)(ImageViewer1.ScaleFactor); for(int i = 0; i < scaleFactors.Length; i++) { _ddlScaleFactor.Items.Add(scaleFactors[i].ToString()); if(factor1 == scaleFactors[i]) _ddlScaleFactor.SelectedIndex = i; } } }

    C#


    Update the Page_Load event handler to be as follows:
    Visual Basic

    Update the Page_Load event handler to be as follows:
    Visual Basic Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not IsPostBack) Then ' Initialize the WebImageViewer control. ImageViewer1.ResourcesPath = "Resources" ImageViewer1.ScrollBarSize = SystemInformation.VerticalScrollBarWidth ' Fill in the Combo Boxes BindDropDownListToEnum(_ddlSizeMode, GetType(ImageViewerSizeMode), ImageViewer1.SizeMode) BindDropDownListToEnum(_ddlHorizontalAlignMode, GetType(ImageViewerAlignMode), ImageViewer1.HorizontalAlignMode) BindDropDownListToEnum(_ddlVerticalAlignMode, GetType(ImageViewerAlignMode), ImageViewer1.VerticalAlignMode) Dim scaleFactors() As Integer = {1000, 800, 600, 400, 200, 100, 75, 50, 25, 10} Dim factor1 As Integer = CInt(ImageViewer1.ScaleFactor) For i As Integer = 0 To scaleFactors.Length - 1 _ddlScaleFactor.Items.Add(scaleFactors(i).ToString()) If (factor1 = scaleFactors(i)) Then _ddlScaleFactor.SelectedIndex = i End If Next End If End Sub
    C# protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { // Initialize the WebImageViewer control. ImageViewer1.ResourcesPath = "Resources"; ImageViewer1.ScrollBarSize = SystemInformation.VerticalScrollBarWidth; // Fill in the Drop-down list boxes BindDropDownListToEnum(_ddlSizeMode, typeof(ImageViewerSizeMode), ImageViewer1.SizeMode); BindDropDownListToEnum(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.HorizontalAlignMode); BindDropDownListToEnum(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.VerticalAlignMode); int[] scaleFactors = { 1000, 800, 600, 400, 200, 100, 75, 50, 25, 10 }; int factor1 = (int)(ImageViewer1.ScaleFactor); for(int i = 0; i < scaleFactors.Length; i++) { _ddlScaleFactor.Items.Add(scaleFactors[i].ToString()); if(factor1 == scaleFactors[i]) _ddlScaleFactor.SelectedIndex = i; } } }

    C# protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { // Initialize the WebImageViewer control. ImageViewer1.ResourcesPath = "Resources"; ImageViewer1.ScrollBarSize = SystemInformation.VerticalScrollBarWidth; // Fill in the Drop-down list boxes BindDropDownListToEnum(_ddlSizeMode, typeof(ImageViewerSizeMode), ImageViewer1.SizeMode); BindDropDownListToEnum(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.HorizontalAlignMode); BindDropDownListToEnum(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode), ImageViewer1.VerticalAlignMode); int[] scaleFactors = { 1000, 800, 600, 400, 200, 100, 75, 50, 25, 10 }; int factor1 = (int)(ImageViewer1.ScaleFactor); for(int i = 0; i < scaleFactors.Length; i++) { _ddlScaleFactor.Items.Add(scaleFactors[i].ToString()); if(factor1 == scaleFactors[i]) _ddlScaleFactor.SelectedIndex = i; } } }
  13. double-click on the _btnGetImageSize, _btnViewImage, _ddlSizeMode, _ddlScaleFactor, _ddlHorizontalAlignMode _ddlVerticalAlignMode, and _btnGetRealScaleFactors controls and update the event handlers as follows:

    Visual Basic


    double-click on the _btnGetImageSize, _btnViewImage, _ddlSizeMode, _ddlScaleFactor, _ddlHorizontalAlignMode _ddlVerticalAlignMode, and _btnGetRealScaleFactors controls and update the event handlers as follows:
    Visual Basic Protected Sub _btnGetImageSize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnGetImageSize.Click Dim queryString As String = String.Format("url={0}", _tbImageUrl.Text) Dim sbResponse As StringWriter = New StringWriter() Dim wr As HttpWorkerRequest = New SimpleWorkerRequest("", queryString, sbResponse) Dim context As HttpContext = New HttpContext(wr) Dim ii As ImageInformation = New ImageInformation() ii.ProcessRequest(context) Dim xmlInfo As XmlDocument = New XmlDocument() If (sbResponse.ToString().Length > 0) Then xmlInfo.LoadXml(sbResponse.ToString()) Dim width As XmlNode = xmlInfo.SelectSingleNode("descendant::Width") Dim height As XmlNode = xmlInfo.SelectSingleNode("descendant::Height") If (Not width Is Nothing) Then _tbImageWidth.Text = width.InnerXml End If If (Not height Is Nothing) Then _tbImageHeight.Text = height.InnerXml End If End If End Sub Protected Sub _btnViewImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnViewImage.Click ImageViewer1.ImageSize = New Size(Convert.ToInt32(_tbImageWidth.Text), Convert.ToInt32(_tbImageHeight.Text)) ImageViewer1.ImageUrl = _tbImageUrl.Text End Sub Protected Sub _ddlSizeMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlSizeMode.SelectedIndexChanged ImageViewer1.SizeMode = GetDropDownListSelectedItem(_ddlSizeMode, GetType(ImageViewerSizeMode)) End Sub Protected Sub _ddlScaleFactor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlScaleFactor.SelectedIndexChanged ImageViewer1.ScaleFactor = Convert.ToInt32(_ddlScaleFactor.SelectedItem.Value) End Sub Protected Sub _ddlHorizontalAlignMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlHorizontalAlignMode.SelectedIndexChanged ImageViewer1.HorizontalAlignMode = GetDropDownListSelectedItem(_ddlHorizontalAlignMode, GetType(ImageViewerAlignMode)) End Sub Protected Sub _ddlVerticalAlignMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlVerticalAlignMode.SelectedIndexChanged ImageViewer1.VerticalAlignMode = GetDropDownListSelectedItem(_ddlVerticalAlignMode, GetType(ImageViewerAlignMode)) End Sub Protected Sub _btnGetRealScaleFactors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnGetRealScaleFactors.Click _tbRealScaleFactors.Text = String.Format("Horizontal:{0}, Vertical:{1}", ImageViewer1.HorizontalRealScaleFactor, ImageViewer1.VerticalRealScaleFactor) End Sub
    C# protected void _btnGetImageSize_Click(object sender, EventArgs e) { string queryString = string.Format("url={0}", _tbImageUrl.Text); StringWriter sbResponse = new StringWriter(); HttpWorkerRequest wr = new SimpleWorkerRequest("", queryString, sbResponse); HttpContext context = new HttpContext(wr); ImageInformation ii = new ImageInformation(); ii.ProcessRequest(context); XmlDocument xmlInfo = new XmlDocument(); if(sbResponse.ToString().Length > 0) { xmlInfo.LoadXml(sbResponse.ToString()); XmlNode width = xmlInfo.SelectSingleNode("descendant::Width"); XmlNode height = xmlInfo.SelectSingleNode("descendant::Height"); if(width != null) { _tbImageWidth.Text = width.InnerXml; } if(height != null) { _tbImageHeight.Text = height.InnerXml; } } } protected void _btnViewImage_Click(object sender, EventArgs e) { ImageViewer1.ImageSize = new Size(Convert.ToInt32(_tbImageWidth.Text), Convert.ToInt32(_tbImageHeight.Text)); ImageViewer1.ImageUrl = _tbImageUrl.Text; } protected void _ddlSizeMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.SizeMode = (ImageViewerSizeMode)GetDropDownListSelectedItem(_ddlSizeMode, typeof(ImageViewerSizeMode)); } protected void _ddlScaleFactor_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.ScaleFactor = Convert.ToInt32(_ddlScaleFactor.SelectedItem.Value); } protected void _ddlHorizontalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.HorizontalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode)); } protected void _ddlVerticalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.VerticalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode)); } protected void _btnGetRealScaleFactors_Click(object sender, EventArgs e) { _tbRealScaleFactors.Text = string.Format("Horizontal:{0}, Vertical:{1}", ImageViewer1.HorizontalRealScaleFactor, ImageViewer1.VerticalRealScaleFactor); }

    C#


    double-click on the _btnGetImageSize, _btnViewImage, _ddlSizeMode, _ddlScaleFactor, _ddlHorizontalAlignMode _ddlVerticalAlignMode, and _btnGetRealScaleFactors controls and update the event handlers as follows:
    Visual Basic

    double-click on the _btnGetImageSize, _btnViewImage, _ddlSizeMode, _ddlScaleFactor, _ddlHorizontalAlignMode _ddlVerticalAlignMode, and _btnGetRealScaleFactors controls and update the event handlers as follows:
    Visual Basic Protected Sub _btnGetImageSize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnGetImageSize.Click Dim queryString As String = String.Format("url={0}", _tbImageUrl.Text) Dim sbResponse As StringWriter = New StringWriter() Dim wr As HttpWorkerRequest = New SimpleWorkerRequest("", queryString, sbResponse) Dim context As HttpContext = New HttpContext(wr) Dim ii As ImageInformation = New ImageInformation() ii.ProcessRequest(context) Dim xmlInfo As XmlDocument = New XmlDocument() If (sbResponse.ToString().Length > 0) Then xmlInfo.LoadXml(sbResponse.ToString()) Dim width As XmlNode = xmlInfo.SelectSingleNode("descendant::Width") Dim height As XmlNode = xmlInfo.SelectSingleNode("descendant::Height") If (Not width Is Nothing) Then _tbImageWidth.Text = width.InnerXml End If If (Not height Is Nothing) Then _tbImageHeight.Text = height.InnerXml End If End If End Sub Protected Sub _btnViewImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnViewImage.Click ImageViewer1.ImageSize = New Size(Convert.ToInt32(_tbImageWidth.Text), Convert.ToInt32(_tbImageHeight.Text)) ImageViewer1.ImageUrl = _tbImageUrl.Text End Sub Protected Sub _ddlSizeMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlSizeMode.SelectedIndexChanged ImageViewer1.SizeMode = GetDropDownListSelectedItem(_ddlSizeMode, GetType(ImageViewerSizeMode)) End Sub Protected Sub _ddlScaleFactor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlScaleFactor.SelectedIndexChanged ImageViewer1.ScaleFactor = Convert.ToInt32(_ddlScaleFactor.SelectedItem.Value) End Sub Protected Sub _ddlHorizontalAlignMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlHorizontalAlignMode.SelectedIndexChanged ImageViewer1.HorizontalAlignMode = GetDropDownListSelectedItem(_ddlHorizontalAlignMode, GetType(ImageViewerAlignMode)) End Sub Protected Sub _ddlVerticalAlignMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ddlVerticalAlignMode.SelectedIndexChanged ImageViewer1.VerticalAlignMode = GetDropDownListSelectedItem(_ddlVerticalAlignMode, GetType(ImageViewerAlignMode)) End Sub Protected Sub _btnGetRealScaleFactors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _btnGetRealScaleFactors.Click _tbRealScaleFactors.Text = String.Format("Horizontal:{0}, Vertical:{1}", ImageViewer1.HorizontalRealScaleFactor, ImageViewer1.VerticalRealScaleFactor) End Sub
    C# protected void _btnGetImageSize_Click(object sender, EventArgs e) { string queryString = string.Format("url={0}", _tbImageUrl.Text); StringWriter sbResponse = new StringWriter(); HttpWorkerRequest wr = new SimpleWorkerRequest("", queryString, sbResponse); HttpContext context = new HttpContext(wr); ImageInformation ii = new ImageInformation(); ii.ProcessRequest(context); XmlDocument xmlInfo = new XmlDocument(); if(sbResponse.ToString().Length > 0) { xmlInfo.LoadXml(sbResponse.ToString()); XmlNode width = xmlInfo.SelectSingleNode("descendant::Width"); XmlNode height = xmlInfo.SelectSingleNode("descendant::Height"); if(width != null) { _tbImageWidth.Text = width.InnerXml; } if(height != null) { _tbImageHeight.Text = height.InnerXml; } } } protected void _btnViewImage_Click(object sender, EventArgs e) { ImageViewer1.ImageSize = new Size(Convert.ToInt32(_tbImageWidth.Text), Convert.ToInt32(_tbImageHeight.Text)); ImageViewer1.ImageUrl = _tbImageUrl.Text; } protected void _ddlSizeMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.SizeMode = (ImageViewerSizeMode)GetDropDownListSelectedItem(_ddlSizeMode, typeof(ImageViewerSizeMode)); } protected void _ddlScaleFactor_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.ScaleFactor = Convert.ToInt32(_ddlScaleFactor.SelectedItem.Value); } protected void _ddlHorizontalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.HorizontalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode)); } protected void _ddlVerticalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.VerticalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode)); } protected void _btnGetRealScaleFactors_Click(object sender, EventArgs e) { _tbRealScaleFactors.Text = string.Format("Horizontal:{0}, Vertical:{1}", ImageViewer1.HorizontalRealScaleFactor, ImageViewer1.VerticalRealScaleFactor); }

    C# protected void _btnGetImageSize_Click(object sender, EventArgs e) { string queryString = string.Format("url={0}", _tbImageUrl.Text); StringWriter sbResponse = new StringWriter(); HttpWorkerRequest wr = new SimpleWorkerRequest("", queryString, sbResponse); HttpContext context = new HttpContext(wr); ImageInformation ii = new ImageInformation(); ii.ProcessRequest(context); XmlDocument xmlInfo = new XmlDocument(); if(sbResponse.ToString().Length > 0) { xmlInfo.LoadXml(sbResponse.ToString()); XmlNode width = xmlInfo.SelectSingleNode("descendant::Width"); XmlNode height = xmlInfo.SelectSingleNode("descendant::Height"); if(width != null) { _tbImageWidth.Text = width.InnerXml; } if(height != null) { _tbImageHeight.Text = height.InnerXml; } } } protected void _btnViewImage_Click(object sender, EventArgs e) { ImageViewer1.ImageSize = new Size(Convert.ToInt32(_tbImageWidth.Text), Convert.ToInt32(_tbImageHeight.Text)); ImageViewer1.ImageUrl = _tbImageUrl.Text; } protected void _ddlSizeMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.SizeMode = (ImageViewerSizeMode)GetDropDownListSelectedItem(_ddlSizeMode, typeof(ImageViewerSizeMode)); } protected void _ddlScaleFactor_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.ScaleFactor = Convert.ToInt32(_ddlScaleFactor.SelectedItem.Value); } protected void _ddlHorizontalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.HorizontalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlHorizontalAlignMode, typeof(ImageViewerAlignMode)); } protected void _ddlVerticalAlignMode_SelectedIndexChanged(object sender, EventArgs e) { ImageViewer1.VerticalAlignMode = (ImageViewerAlignMode)GetDropDownListSelectedItem(_ddlVerticalAlignMode, typeof(ImageViewerAlignMode)); } protected void _btnGetRealScaleFactors_Click(object sender, EventArgs e) { _tbRealScaleFactors.Text = string.Format("Horizontal:{0}, Vertical:{1}", ImageViewer1.HorizontalRealScaleFactor, ImageViewer1.VerticalRealScaleFactor); }
  14. Add the following functions to the end of the "Default.aspx.cs" file (for C#) or before the "End Class" statement (for Visual Basic):

    Visual Basic


    Add the following functions to the end of the "Default.aspx.cs" file (for C#) or before the "End Class" statement (for Visual Basic):
    Visual Basic Private Sub BindDropDownListToEnum(ByVal ddl As DropDownList, ByVal t As Type, ByVal selected As Object) Dim a As Array = [Enum].GetValues(t) ddl.DataSource = a ddl.DataBind() Dim selectedValue As String = selected.ToString() For i As Integer = 0 To ddl.Items.Count - 1 If (ddl.Items(i).Value = selectedValue) Then ddl.SelectedIndex = i Return End If Next End Sub Private Function GetDropDownListSelectedItem(ByVal ddl As DropDownList, ByVal t As Type) As Object Return [Enum].Parse(t, ddl.SelectedItem.Value) End Function
    C# private void BindDropDownListToEnum(DropDownList ddl, Type t, object selected) { Array a = Enum.GetValues(t); ddl.DataSource = a; ddl.DataBind(); string selectedValue = selected.ToString(); for(int i = 0; i < ddl.Items.Count; i++) { if(ddl.Items[i].Value == selectedValue) { ddl.SelectedIndex = i; return; } } } private object GetDropDownListSelectedItem(DropDownList ddl, Type t) { return Enum.Parse(t, ddl.SelectedItem.Value); }

    C#


    Add the following functions to the end of the "Default.aspx.cs" file (for C#) or before the "End Class" statement (for Visual Basic):
    Visual Basic

    Add the following functions to the end of the "Default.aspx.cs" file (for C#) or before the "End Class" statement (for Visual Basic):
    Visual Basic Private Sub BindDropDownListToEnum(ByVal ddl As DropDownList, ByVal t As Type, ByVal selected As Object) Dim a As Array = [Enum].GetValues(t) ddl.DataSource = a ddl.DataBind() Dim selectedValue As String = selected.ToString() For i As Integer = 0 To ddl.Items.Count - 1 If (ddl.Items(i).Value = selectedValue) Then ddl.SelectedIndex = i Return End If Next End Sub Private Function GetDropDownListSelectedItem(ByVal ddl As DropDownList, ByVal t As Type) As Object Return [Enum].Parse(t, ddl.SelectedItem.Value) End Function
    C# private void BindDropDownListToEnum(DropDownList ddl, Type t, object selected) { Array a = Enum.GetValues(t); ddl.DataSource = a; ddl.DataBind(); string selectedValue = selected.ToString(); for(int i = 0; i < ddl.Items.Count; i++) { if(ddl.Items[i].Value == selectedValue) { ddl.SelectedIndex = i; return; } } } private object GetDropDownListSelectedItem(DropDownList ddl, Type t) { return Enum.Parse(t, ddl.SelectedItem.Value); }

    C# private void BindDropDownListToEnum(DropDownList ddl, Type t, object selected) { Array a = Enum.GetValues(t); ddl.DataSource = a; ddl.DataBind(); string selectedValue = selected.ToString(); for(int i = 0; i < ddl.Items.Count; i++) { if(ddl.Items[i].Value == selectedValue) { ddl.SelectedIndex = i; return; } } } private object GetDropDownListSelectedItem(DropDownList ddl, Type t) { return Enum.Parse(t, ddl.SelectedItem.Value); }
  15. From the path "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32", copy the Leadtools.Codecs.Bmp, Leadtools.Codecs.Gif, Leadtools.Codecs.Png and Leadtools.Codecs.Cmp DLLs to the project's Bin folder.

  16. Inside the project folder create a folder named "Resources" and copy all of the java script files and images found in the "<LEADTOOLS_INSTALLDIR>\Examples\DotNet\Resources\Web" folder to it.

  17. Run the project and play with it as follows:

    • Type a path to one of the Internet Browser supported formats (gif, bmp, png or jpeg) in the ImageUrl TextBox.

    • Click GetImageSize to update the ImageWidth and ImageHeight Text Boxes by the image width and height.

    • Click ViewImage to load the image into the WebImageViewer control.

    • Change the selected items in the drop-down list boxes and notice the differences in the displayed image.

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.