By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

Drawing a rectangle on a web page

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Ryan" <an*******@discussions.microsoft.com> wrote in message news:09****************************@phx.gbl...
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
Nov 16 '05 #2

P: n/a
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" <an*******@discussions.microsoft.com> wrote in message news:09****************************@phx.gbl...
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 prettymuch have to either (a) throw out that Windows code altogether,or (b) salvage it perhaps by using WinForms graphics code torender drawings to a Bitmap and then save off that Bitmap (asa .jpg, .gif, or other graphics file format) to some location on theweb server that clients can reach (be careful if you do save afile from your Web application that the ASPNET account hassecurity privileges granted to it sufficient enough to create theimage file on the server's file system).

If there's a dynamically generated image file on the server for theWeb Form to refer to using an IMG tag, then it's simply a matterof rendering <IMG SRC="url_of_your_graphics_file.png" /> out tothe HTTP response stream when the page renders. This still carriesthe problem of how to clean-up after such dynamically generatedfiles, though (because of ASP.NET's inherent statelessness).
Nothing in that Windows function will give you a clue about the Webenvironment. In an ASP.NET WebForms application, you muchrender HTML markup to the client's web browser -- this is all textthat describes what the page should look like. Browsers like InternetExplorer, Mozilla, and Firefox all interpret the HTML and display itto your end user (sometimes these browsers will interpret the HTMLin 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 interactwith. However, the exact characteristics of a button to a user onInternet Explorer / Windows XP with an Olive color scheme willdiffer from the appearance of a button to a user on Firefox /Macintosh. As a web developer, you usually don't have controlover what peer exactly the browser chooses to represent yourHTML elements as.

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

<table border="1"><tr><td> </td></tr></table>

What you could do in Visual Studio .NET is create a Web
Custom Control library (using that project type), overridethe Render method in the class file it produces for you towrite that string above to the HtmlTextWriter argument it
receives, then build this library. Next, open the Toolboxwith 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 InternetExplorer 5 (but no other brands of browser). SVG is the
heir to the throne, but it still requires that you install a plugin 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 thedifferences between ASP.NET and WinForms, rushing
headlong into these specialty markup languages may be
premature though.
Derek Harmon
.

Nov 16 '05 #3

P: n/a
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

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.