Click here to Skip to main content
15,946,342 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am working on a C# web application. I need to select/highlight some area on an image on focus of a textbox, and then de-select the area when the focus is lost. I have been able to do so on click of a button, by using bitmap and Graphics object. But I cant do the same on textbox onfocus event.

I had used the following code written inside a static server side function :

Bitmap bmp = (Bitmap)Bitmap.FromFile("~/Images/SampleDoc.jpg");
Graphics g = Graphics.FromImage(bmp);

Pen snowPen = new Pen(Color.Blue, 2);
g.DrawRectangle(snowPen, 600, 225, 100, 30);
//g.DrawRectangle(Pen, x, y, width, height);

String path = Server.MapPath("~/Images/DrawRectangle.jpg");
bmp.Save(path, ImageFormat.Jpeg);

Image1.ImageUrl = "~/Images/DrawRectangle.jpg";

and called it using a javascipt function.

I tried using the code above for a textbox focus too but I wasn't able to access the Server object and Image1 object.

I am pretty new to and javascript. Any help will be much appreciated.

Thanks in advance.

Gitika Khurana


See below link. It might be help you.

Modal PopUp in Image map[^]

Share this answer
gitika.khurana 7-Sep-12 6:17am    
I am not looking for the functionality offered by ImageMap. I don't need to click anywhere on the image. All I want is to be able to highlight some area on the image, not create a hotspot.
You have to use some library in javascript.
You have to map the image with "map" tag, and use javascript for animate it.

this is a sample example using jQuery:[^]

you can also search on google, or visit this project:[^]</map>
Share this answer
gitika.khurana 10-Sep-12 3:08am    
Thanks for the reply, but it doesn't really solve my purpose. Image maps work with mouseover, and I am looking for image area highlight on textbox focus.
cpsglauco 20-Sep-12 9:07am    
if you read some example from the netzgesta library, you will find scripts that fit your needs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900