April 19, 2019
Hot Topics:

Rendering Graphics in ASP.NET with GDI+

  • March 26, 2007
  • By Paul Kimmel
  • Send Email »
  • More Articles »

Showing the Dynamic Image

To render the image, you can create a page—the example calls ClockPage.aspx—and drag and drop the ClockControl onto the ClockPage (see Figure 2).

Figure 2: The Dynamically Drawn Image of a Simple Analog Clock

When the ClockPage.aspx page is requested, the ClockControls Page_Load calls DrawClock. To ensure the ClockPage is requested, you assign it instead of an actual image to the source property of an <img> control (keeping in mind that an Image web control is rendered as an <img> HTML tag). Listing 3 shows the markup for the ClockPage.

Listing 3: The Markup for the clockpage.sspx Page

<%@ Page Language="VB" AutoEventWireup="false"
         CodeFile="ClockPage.aspx.vb" Inherits="ClockPage" %>
<%@ Register Src="ClockControl.ascx"
             TagName="ClockControl" TagPrefix="uc1" %>
<%@ OutputCache NoStore="true" Duration="1" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Untitled Page</>title>
   <form id="form1" runat="server">
      <uc1:ClockControl ID="ClockControl1" runat="server"
                        EnableViewState="false" />

I'll leave the final challenge of animating the clock as real-time feedback for another article. As is, the user would have to refresh the page every time an update clock was desired.

The Clock Is Drawn

This example demonstrated how you can treat a dynamic image on a UserControl as a drawing surface much as you'd treat a Windows form as one. The user control is then embedded on a page, and that page becomes the source value of an image attribute. Each time the source attribute—I used the <img src="clockpage.aspx" /> tag—requested and the image is to be rendered, the clock will be redrawn.

About the Author

Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object-oriented programming and .NET. Check out his new book UML DeMystified from McGraw-Hill/Osborne. Paul is a software architect for Tri-State Hospital Supply Corporation. You may contact him for technology questions at pkimmel@softconcepts.com.

If you are interested in joining or sponsoring a .NET Users Group, check out www.glugnet.org.

Copyright © 2007 by Paul T. Kimmel. All Rights Reserved.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date