Drawing in Custom Controls

Q

Qwert

Heya,

I have a cusom control:

Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl5
runat=server></{0}:WebCustomControl5>")> Public Class WebCustomControl5
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
...
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write([Text])
End Sub
End Class

I want to draw graphics (bmp's) in 'Render'. How is this done? In VB.NET
controls you could do things like:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
With e.Graphics
.DrawImage(...)
End With
End Sub

Any help/links appriciated,

mr noob.
 
G

Guest

Hi Qwert,

SORRY this cannot be done in ASP.Net. The output of an ASPX file is HTML,
and no binary data. You can create a HttpHandler which creates an image on
the fly and than reference to it with a System.Web.UI.WebControls.Image or a
simple <img>-Tag.

e.g. <img src="MyImageCreator.ashx" />

this article could help:
http://weblogs.asp.net/cazzu/archive/2003/08/27/25568.aspx
 
Q

Qwert

Thanks. I now draw everything and then send the result with <img> tag
indeed.


Patrick said:
Hi Qwert,

SORRY this cannot be done in ASP.Net. The output of an ASPX file is HTML,
and no binary data. You can create a HttpHandler which creates an image on
the fly and than reference to it with a System.Web.UI.WebControls.Image or
a
simple <img>-Tag.

e.g. <img src="MyImageCreator.ashx" />

this article could help:
http://weblogs.asp.net/cazzu/archive/2003/08/27/25568.aspx

Qwert said:
Heya,

I have a cusom control:

Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl5
runat=server></{0}:WebCustomControl5>")> Public Class WebCustomControl5
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
...
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write([Text])
End Sub
End Class

I want to draw graphics (bmp's) in 'Render'. How is this done? In VB.NET
controls you could do things like:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
With e.Graphics
.DrawImage(...)
End With
End Sub

Any help/links appriciated,

mr noob.
 
K

Kevin Spencer

Hi mr. noob,

You might want to put down that custom control for a bit, and familiarize
yourself with your UI. It's a web page. If you're not familair with web
pages and HTML, you're going to have beaucoups trouble. Why? Because a web
page is not a VB6 executable sitting on your machine. It is a TEXT document.
Next time you're using your browser, view the souce code for the page.
First, make sure there are images in it, so you can see this for yourself.
Note that the TEXT document that is the HTML page has no images in it. Of
course, how could it? Its a text document.

So, where do the images come from, and how do they get into the browser, in
the right places in the document? It is via an image tag in the markup.
Example:

<img src="/images/someimage.jpg">

Now, as the browser is displaying an HTML document, where does the image
come from? It is downloaded from the specified URL in the image tag and
rendered in the browser BY the browser.

So, how do you draw in an ASP.Net page? The answer is, you don't. You draw
an image on the server, and stream it to the browser when requested.

How is this done in an ASPX page? Well, you need to create another ASPX page
that serves as the "image." When this page is requested, it draws an image
on the server side, sets the Response.ContentType to "image/jpg" (the
correct MIME type for that image type), and saves the image to the
Response.OutputStream. The browser, which ordinarily derives what type of
file it is receiving from the file extension, will instead read the
ContentType header, and display the binary output as an image.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top