Drawing a rectangle on a web page

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

Hello,

I'm trying to draw a rectangle on a web page which
contains a picture. Following is the function for a
similar windows application.

private void ZoomIn_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
System.Drawing.Graphics g ;
g = Graphics.FromHwnd(this.MapImage.Handle) ;
Rectangle TheRect = GetTheRectangle(StartBoxPoint,
EndBoxPoint) ;
g.DrawRectangle(this.ThePen, TheRect) ;
RefreshImage(StartBoxPoint.X, StartBoxPoint.Y,
EndBoxPoint.X, EndBoxPoint.Y) ;
g.Dispose();
}

When I'm building the solution its giving me an error
System.Web.UI.Webcontrols.Image doesn't contain a
definition for handle.

Can anyone please help me on this issue?

Regards,
Ryan
 
Ryan said:
I'm trying to draw a rectangle on a web page which
contains a picture. Following is the function for a
similar windows application. : :
When I'm building the solution its giving me an error
System.Web.UI.Webcontrols.Image doesn't contain a
definition for handle.

There are a number of fundamental differences between Windows
(rich client) graphics and Web (thin client) graphics. You pretty
much have to either (a) throw out that Windows code altogether,
or (b) salvage it perhaps by using WinForms graphics code to
render drawings to a Bitmap and then save off that Bitmap (as
a .jpg, .gif, or other graphics file format) to some location on the
web server that clients can reach (be careful if you do save a
file from your Web application that the ASPNET account has
security privileges granted to it sufficient enough to create the
image file on the server's file system).

If there's a dynamically generated image file on the server for the
Web Form to refer to using an IMG tag, then it's simply a matter
of rendering <IMG SRC="url_of_your_graphics_file.png" /> out to
the HTTP response stream when the page renders. This still carries
the problem of how to clean-up after such dynamically generated
files, though (because of ASP.NET's inherent statelessness).

Nothing in that Windows function will give you a clue about the Web
environment. In an ASP.NET WebForms application, you much
render HTML markup to the client's web browser -- this is all text
that describes what the page should look like. Browsers like Internet
Explorer, Mozilla, and Firefox all interpret the HTML and display it
to your end user (sometimes these browsers will interpret the HTML
in varied and unexpected ways! Web progamming isn't just a job,
it's a neverending epic adventure ...) Usually they create peer con-
trols using the end user's own operating system's rich graphics sub-
system, that correspond to HTML elements that a user can interact
with. However, the exact characteristics of a button to a user on
Internet Explorer / Windows XP with an Olive color scheme will
differ from the appearance of a button to a user on Firefox /
Macintosh. As a web developer, you usually don't have control
over what peer exactly the browser chooses to represent your
HTML elements as.

To draw a box in HTML, you would render this markup,

<table border="1"><tr><td>&nbsp;</td></tr></table>

What you could do in Visual Studio .NET is create a Web
Custom Control library (using that project type), override
the Render method in the class file it produces for you to
write that string above to the HtmlTextWriter argument it
receives, then build this library. Next, open the Toolbox
with Control-Alt-X key, and Customize one of the tabs,
so that you can Add a .NET Framework component.
Browse until you find the .dll file that you just created,
the Custom Control library, and drag and drop that
onto your WebForm1.aspx's Design View. You should
see a preview of the box at design-time, similar to what
it would look like at run-time.

Other subjects you may want to investigate for more
information are VML (Vector Markup Language) and
it's successor, SVG (Scalable Vector Graphics). VML
is obsolete but it has the benefit of being built-in to Internet
Explorer 5 (but no other brands of browser). SVG is the
heir to the throne, but it still requires that you install a plug
in to make your browser display SVG (Adobe offers one
free plug-in for SVG on Internet Explorer, there are also
other plug-ins out there for SVG on Mozilla and Firefox
brands of browser.) Until you have a tighter grasp of the
differences between ASP.NET and WinForms, rushing
headlong into these specialty markup languages may be
premature though.


Derek Harmon
 
Hello Derek,

Thank you very much for giving me a detailed information
on creating graphics on a web form.

let me explain the issue in a detailed way.
I'm creating a web page which will display the MAP as a
JPG file. I want to create an ZOOM IN event - when the
user clicks on 'zoom in' button, he should be able to
draw a rectangle on the map. The program should also
capture the starting and ending points of the rectangle,
so that I can pass the co-ordinates to the server which
will get me the new image.

I think the best option is to throw out the windows code
all together and build a new one.

Any help would be really appreciated.

Regards
Ryan
-----Original Message-----
"Ryan" <[email protected]> wrote in
message news:[email protected]...
 
Ryan,
I don't know the answer to this, but I _do_ know that the C# newsgroup
isn't the best for handling the advanced DHTML question. I would
suggest trying a DHTML, javascript, or at least the ASP.NET newsgroup.
Sorry I couldn't be of more help.


Best regards,
Jeffrey Palermo
http://www.jeffreypalermo.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top