Jake Gaston
Jake Gaston

Reputation: 211

drawing lines on screen?

I've been reading through a few asp.net articles, and attempting some code, but I think I may be confused. Can you or can you not draw lines on the screen with code on a ASP.NET webform using c#?

If so, can anyone direct me to some examples?

Upvotes: 2

Views: 2074

Answers (6)

tonyellard
tonyellard

Reputation: 156

You could probably create a new image using the System.Drawing namespace classes and then do something like dynamically load it into an <img /> tag...but depending on what you're trying to accomplish it may be far easier to either use a JavaScript library of some sort or to use some sort of very simple line image and tweak the length/height using css.

More detail would be needed to understand what you're trying to do. As others have pointed out though, there's no direct way for your C# code to interact with the page. You'd have to have something on the page like an img tag and then set it's source to a C# file like a handler (.ashx). In that handler you could generate the image and then set the response content type as image/jpg and write the raw bytes to the response stream...

Again though, that seems like overkill for something that could be accomplished with CSS or javascript.

Upvotes: 0

Antonio Bakula
Antonio Bakula

Reputation: 20693

Because there is not screen for your server side code. Your code generates HTML, JavaScript etc. and then browser uses that content to render it on the client screen. So your options are to generate image (draw all that you need) in server side code and send it to the browser, or you can use JavaScript and send browser instructions how to draw lines.

Upvotes: 0

smurtagh
smurtagh

Reputation: 529

Not sure what you mean by "draw a line" but if you are using a web browser you need some kind of HTML object to display this "line". If all you need is a horizontal line you can just add a HR html tag and use CSS toy stylize it. You can also include this line in an image or HTML5 Canvas.

Upvotes: 0

Firoz Ansari
Firoz Ansari

Reputation: 2515

If you are fine with HTML5 you can try lineto Javascript method:

<script>
  context.lineTo(100, 200);
</script>

Please refer @ following link for more details: http://www.html5canvastutorials.com/tutorials/html5-canvas-lines/

Upvotes: 1

coder
coder

Reputation: 13248

You can make a canvas and then you can draw whatever you want to draw on it.But direct drawing is impossible.

Upvotes: 1

empi
empi

Reputation: 15901

You cannot directly draw on a webform. You may draw on the image and then embed it on your webform (like any other image).

Upvotes: 4

Related Questions