Draw an x mark on image in asp net using c sharp


ASP.NET is a popular used for web applications. In this article, we will explore how to draw an x mark on an image using C# in ASP.NET.

Step 1: Adding an Image Control

To , we need to add an image control to our ASP.NET page. This control will display the image on which we want to draw the x mark. Here is an example of how to add an image control:

Step 2: Drawing the X Mark

Next, we need to write the code to draw the x mark on the image. We can achieve this by the image control's Paint event. Here is an example of how to do it:

 void imgExample_Paint(object sender, PaintEventArgs e)
    Graphics g = e.Graphics;
    Pen pen = new Pen(Color.Red, 2);
    // Draw the first line of the x mark
    g.DrawLine(pen, 0, 0, imgExample.Width, imgExample.Height);
    // Draw the second line of the x mark
    g.DrawLine(pen, imgExample.Width, 0, 0, imgExample.Height);

In the above code, we first create a Graphics object and a Pen object with the desired color and thickness. Then, we use the DrawLine method to draw the two lines that form the x mark on the image.

Step 3: Registering the Paint Event

Finally, we need to register the Paint event for the image control. This can be done in the Page_Load event handler. Here is an example:

protected void Page_Load(object sender, EventArgs e)
    imgExample.Paint += new PaintEventHandler(imgExample_Paint);

By registering the Paint event, we that the code in the imgExample_Paint method is whenever the image control to be painted on the page.


In this article, we have learned how to draw an x mark on an image in ASP.NET using C#. By following the steps outlined above, you can easily implement this functionality in your web application. Remember to adjust the code according to your specific and image dimensions.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents