I'm going to show a error message in my program .
I'd like my messages to be like image below,
as you can see, I need a dark shadow to be shown when message pops up .
I follow two solution to do this :
1 - I take a screenshot of program (and I mix it with a black color, to be bit a dark) and then I attach it to a panel and I show the panel and then message form pops up . it doesn't work because sometimes it takes screenshot from other programs that is on the screen (for example telegram notifications)
2 - I use a rich panel (that I got from internet) that it can have opacity property, and then I set panel's color to black and opacity to 0.5. then I pop up the message. it doesn't work because this new panel does not cover all elements (IDK why !)
both of this solutions had some problems and did not work . Is there any solution to show such this messages ?
im using win forms not WPF
this my riched panel :
public class ExtendedPanel : Panel
{
private const int WS_EX_TRANSPARENT = 0x20;
public ExtendedPanel()
{
SetStyle(ControlStyles.Opaque, true);
}
private int opacity = 50;
[DefaultValue(50)]
public int Opacity
{
get
{
return this.opacity;
}
set
{
if (value < 0 || value > 100)
throw new ArgumentException("value must be between 0 and 100");
this.opacity = value;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
using (var brush = new SolidBrush(Color.FromArgb(this.opacity * 255 / 100, this.BackColor)))
{
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
base.OnPaint(e);
}
}
this is how i use it :
using (ExtendedPanel p = new ExtendedPanel())
{
p.Location = new Point(0, 0);
p.Size = f.ClientRectangle.Size;
p.BackgroundImage = bmp;
e.f.Controls.Add(p);
//e.p = p;
p.BringToFront();
e.StartPosition = FormStartPosition.CenterParent;
e.lblTitr.Text = header;
e.lblText.Text = text;
e.ShowDialog(f);
// p.Visible = false;
// e.f.Controls.Remove(p);
e.f.Controls.Remove(p);
e.f.Refresh();
}