Sunday, August 15, 2010

How to zoom in/out an image using asp.net

It is necessary to hold width and height in ViewState variables in-order to hold width and height values during postbacks.
Example:
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">    
    <script runat="server">
        private double swift = 10;
        public void ChangeSize(object sender, EventArgs e)
        {
            double w = this.imgDisplay.Width.Value;
            double h = this.imgDisplay.Height.Value;
            Button button = sender as Button;
            if (button.CommandName.Equals("ZI"))
            {
                h += swift;
                w += swift;
            }
            else if (button.CommandName.Equals("ZO"))
            {
                w -= swift;
                h -= swift;
            }
            this.imgDisplay.Height = new Unit(h);
            this.imgDisplay.Width = new Unit(w);
        }        
    </script>
</head>
<body>    
    <form id="form2" runat="server">  
        <asp:Image runat="server" ID="imgDisplay" ImageUrl="~/Images/Charith.jpg" Width="100px" Height="100px" />
        <asp:Button runat="server" ID="btnZoomIn" OnClick="ChangeSize" Text="+" CommandName="ZI" />
        <asp:Button runat="server" ID="btnZoomOut" OnClick="ChangeSize" Text="-" CommandName="ZO" />        
    </form>
</body>

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...