After much thought I decided to change the focus and instead of marking the component with the selected boxes (corners and sides) use the cursor in the form of resized arrows to indicate that it is resized.
In addition, I managed to implement the resizing in the following way:
NOTE : In my case the mouse button that does the resizing is the central one. For other buttons change MouseButtons.Middle by its corresponding value
Variables within the class inherited from Form
public partial class Principal : Form
{
private Boolean redimensionandoCuadroImagen = false;
private int marginRedimension = 10;
private Size tamanoInicioCuadroImagen;
private Rectangle rectaPunteadaApoyoRedimensionCuadroImagen = Rectangle.Empty;
private Point puntoInicioArrastreRedimensionCuadroImagen;
private Control objetoArrastradoCuadroImagen = null;
...... // Resto de variables
Method that receives the event of the click on the component (PictureBox)
private void pulsarEnPictureBox(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
locationCuadroImagen = new Point(e.X, e.Y);
}
else
{
if (e.Button == MouseButtons.Middle)
{
objetoArrastradoCuadroImagen = (Control)sender;
// Si el click se ha hecho dentro de los margenes cercanos al perimetro del control
if ((e.X <= marginRedimension) || (e.X >= objetoArrastradoCuadroImagen.Width - marginRedimension) ||
(e.Y <= marginRedimension) || (e.Y >= objetoArrastradoCuadroImagen.Height - marginRedimension))
{
// Activamos la redimension y cambiamos el cursor
redimensionandoCuadroImagen = true;
this.Cursor = Cursors.SizeNWSE;
// Tamaño inicial
this.tamanoInicioCuadroImagen = new Size(e.X, e.Y);
// Obtenemos la localizacion del control
Point pt = this.PointToScreen(objetoArrastradoCuadroImagen.Location);
// Creamos el rectangulo pestunteado y lo pintamos
rectanguloPunteadaApoyoRedimensionCuadroImagen = new Rectangle(pt, tamanoInicioCuadroImagen);
ControlPaint.DrawReversibleFrame(rectanguloPunteadaApoyoRedimensionCuadroImagen, this.ForeColor, FrameStyle.Dashed);
}
else
{
redimensionandoCuadroImagen = false;
this.Cursor = Cursors.Default;
}
// Obtenemos el punto de inicio del arrastre
this.puntoInicioArrastreRedimensionCuadroImagen = e.Location;
}
}
}
Method that receives the drag event with the mouse in the component (PictureBox)
private void moverEnPictureBox(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (locationCuadroImagen != Point.Empty)
{
PictureBox cuadro = (PictureBox)sender;
Point newlocation = cuadro.Location;
newlocation.X += e.X - locationCuadroImagen.X;
newlocation.Y += e.Y - locationCuadroImagen.Y;
cuadro.Location = newlocation;
}
}
else
{
if (e.Button == MouseButtons.Middle)
{
if (objetoArrastradoCuadroImagen != null)
{
if (redimensionandoCuadroImagen)
{
// Movemos el rectangulo pespunteado
if (rectanguloPunteadaApoyoRedimensionCuadroImagen.Width > 0 && rectanguloPunteadaApoyoRedimensionCuadroImagen.Height > 0)
ControlPaint.DrawReversibleFrame(rectanguloPunteadaApoyoRedimensionCuadroImagen, this.ForeColor, FrameStyle.Dashed);
rectanguloPunteadaApoyoRedimensionCuadroImagen.Width = e.X - this.puntoInicioArrastreRedimensionCuadroImagen.X + this.tamanoInicioCuadroImagen.Width;
rectanguloPunteadaApoyoRedimensionCuadroImagen.Height = e.Y - this.puntoInicioArrastreRedimensionCuadroImagen.Y + this.tamanoInicioCuadroImagen.Height;
if (rectanguloPunteadaApoyoRedimensionCuadroImagen.Width > 0 && rectanguloPunteadaApoyoRedimensionCuadroImagen.Height > 0)
ControlPaint.DrawReversibleFrame(rectanguloPunteadaApoyoRedimensionCuadroImagen, this.ForeColor, FrameStyle.Dashed);
}
}
}
}
}
Method that receives the event of raising the mouse button on the component (PictureBox)
private void soltarEnPictureBox(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
if (redimensionandoCuadroImagen)
{
if (rectanguloPunteadaApoyoRedimensionCuadroImagen.Width > 0 && rectanguloPunteadaApoyoRedimensionCuadroImagen.Height > 0)
{
// Borramos el rectangulo pespunteado
ControlPaint.DrawReversibleFrame(rectanguloPunteadaApoyoRedimensionCuadroImagen, this.ForeColor, FrameStyle.Dashed);
}
// Comparamos si hemos redimensionado por debajo de los minimos en cuyo caso redimensionaremos al los minimos
if (rectanguloPunteadaApoyoRedimensionCuadroImagen.Width > 100 && rectanguloPunteadaApoyoRedimensionCuadroImagen.Height > 100)
{
// Tamaño seleccionado
this.objetoArrastradoCuadroImagen.Size = rectanguloPunteadaApoyoRedimensionCuadroImagen.Size;
}
else
{
// Tamaño minimo
this.objetoArrastradoCuadroImagen.Size = new Size((int)Math.Max(100, rectanguloPunteadaApoyoRedimensionCuadroImagen.Width), Math.Max(100, rectanguloPunteadaApoyoRedimensionCuadroImagen.Height));
}
}
// Ponemos las variables a su valor por defecto
this.objetoArrastradoCuadroImagen = null;
this.puntoInicioArrastreRedimensionCuadroImagen = Point.Empty;
this.Cursor = Cursors.Default;
}
}