I want to highlight particular part of image in a picturebox control in run time of the application.How can i implement this one using c#?
Asked
Active
Viewed 5,006 times
2 Answers
1
Here there is an example that draws an alpha rectangle hover the picturebox when the user moves the mouse hover the image. Note that you can highlight the picture as you want.
public partial class Form2 : Form
{
private Rectangle mHoverRectangle = Rectangle.Empty;
private const int HOVER_RECTANGLE_SIZE = 20;
public Form2()
{
InitializeComponent();
pictureBox.MouseMove += new MouseEventHandler(pictureBox_MouseMove);
pictureBox.Paint += new PaintEventHandler(pictureBox_Paint);
pictureBox.MouseLeave += new EventHandler(pictureBox_MouseLeave);
}
void pictureBox_MouseLeave(object sender, EventArgs e)
{
mHoverRectangle = Rectangle.Empty;
}
void pictureBox_Paint(object sender, PaintEventArgs e)
{
if (mHoverRectangle != Rectangle.Empty)
{
using (Brush b = new SolidBrush(Color.FromArgb(150, Color.White)))
{
e.Graphics.FillRectangle(b, mHoverRectangle);
}
}
}
void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
mHoverRectangle = new Rectangle(
e.Location.X - HOVER_RECTANGLE_SIZE / 2,
e.Location.Y - HOVER_RECTANGLE_SIZE / 2,
HOVER_RECTANGLE_SIZE,
HOVER_RECTANGLE_SIZE);
pictureBox.Invalidate();
}
}
Hope it helps

Daniel Peñalba
- 30,507
- 32
- 137
- 219
-
how can i highlight particular part of an image in picturebox at run time..? – Praveen Kumar Aug 21 '12 at 10:44
-
The example I wrote highlights a rectangle around the mouse pointer. If you want to highlight a fixed part of the rectangle, you need to define the portion in the mHoverRectangle variable. – Daniel Peñalba Aug 21 '12 at 10:52
-
k..Is it possible to blink particular part of a image in picturebox? – Praveen Kumar Aug 21 '12 at 11:46
-
1Yes, you can take a part of the image. Then create a Timer and using a delay of 1 second, for example, highlight and unhightlight the image. Here is a link about how to use the Timer: http://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.80).aspx – Daniel Peñalba Aug 21 '12 at 12:25
0
Try this : Clicking a control and causing it to shade
In the selected answer instead of getting each pixel and shading it, take a part of the picture and shade it. Hope it helps.

Community
- 1
- 1

MaxDataSol
- 358
- 1
- 2
- 18