i am implementing the solution from Reza Aghaei from this post Creating Custom Picturebox with Draggable and Resizable Selection Window.
i am triggering the selection control from a menu button, the rectangle selection works fine, but i don't know how trigger the part where he add the "fancy effect of filling outside of the frame with semi-transparent color", i want this happend after i pressing the button to load the resizable control.
the code of that part is this:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);
}
and this is my function to load the custom control
private void selectToolStart(object sender, EventArgs e)
{
var s = 100;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
}
Any advice is welcome. Thanks in advance
UPDATE:
After all the help from you guys, i came with this code:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (pictureBox1.HasChildren == true)
{
e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);
}
pictureBox1.Invalidate();
}
UPDATE 2
Taking the advice from TaW i move the invalidate from paint event to selectToolStart() function. so this time the code stay as follow
private void selectToolStart(object sender, EventArgs e)
{
var s = 100;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
pictureBox1.Invalidate();
}
and the Paint event stay as follow
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (pictureBox1.HasChildren == true)
{
e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
{
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);
}
}
}
It seems it get the job done. any feedback or suggestion please. Thanks all you guys.