The main thing about "highlighting" either on images or controls is that you need to gain access to a graphics object. To get one for a bitmap you can do:
g = Graphics.FromImage(myBitmap);
g.DrawRectangle(Pens.Red, 0, 0, 100, 100);
g.Dispose();
Here is some code that uses the same principle but with a picturebox control in order to work with mouse movements in C#.
private bool expanding;
private bool selectActive = false;
private Point selectStart;
private Point selectPosition;
private bool selecting;
private bool selectionExists;
private bool manualFinding;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (!selectActive)
{
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
selectStart = e.Location;
selecting = true;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (selecting)
{
selectPosition = e.Location;
pictureBox1.Invalidate();
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int x = Math.Min(selectStart.X, selectPosition.X);
int y = Math.Min(selectStart.Y, selectPosition.Y);
int w = Math.Abs(selectStart.X - selectPosition.X);
int h = Math.Abs(selectStart.Y - selectPosition.Y);
if (selectionExists || selecting)
{
e.Graphics.DrawRectangle(Pens.Red, x, y, w, h);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (!selecting)
{
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
selecting = false;
selectionExists = true;
}
}
Here is a different example of how you might create a control that can draw an image, but then where you can draw arbitrary stuff on top of the image during each invocation of the paint event:
public class ImageControl : Control
{
[Description("The base image for this control to render.")]
public Bitmap Image { get; set; }
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// base.OnPaintBackground(pevent);
}
/// <summary>
/// Override paint so that it uses your glow regardless of when it is instructed to draw
/// </summary>
/// <param name="pevent"></param>
protected override void OnPaint(PaintEventArgs pevent)
{
pevent.Graphics.DrawImage(Image, 0, 0, Width, Height);
pevent.Graphics.DrawLine(Pens.Blue, 0, 0, 100, 100);
}
}