Hello,
I am trying to come up with a way to blur the entire screen (all forms visible) on a WinForms program. I am using C# in VS2005. I have tried the code from this link:
.net - C# dialog form with blur background - Stack Overflow
...and it works quite well, however it only works for the active form, not for all forms visible. How would I adapt this code to work for the entire screen? I looked at
the Application.OpenForms[] controls, but I can only do one control.
Is there a more elegant way to do what I'm trying to achieve?
Loading
VulpesPosted Sep 25, 2014, 7:06 PM
Mike McWhinneyPosted Sep 25, 2014, 6:57 PM
Do I need to add the IBlur reference to every form?
When I run my program as is, an exception is generated:
Unable to cast object of type 'WindowsApplication1.AppointmentDetailForm' to type 'WindowsApplication1.IBlur'.
The exception is in this code:
private void BlurAll()
{
foreach (Form f in Application.OpenForms)
{
((IBlur)f).Blur();
}
}
When I tried in this form to add the IBlur interface to the form in this fashion:
public partial class PatientSummaryForm : Form, IBlur
I get this error when trying to compile:
Error 106 'WindowsApplication1.PatientSummaryForm' does not implement interface member 'WindowsApplication1.IBlur.Blur()' E:\c# projects\Eclipse\Scheduler\Oslerscheduler\OslerScheduler\PatientSummaryForm.Designer.cs 3 19 OslerScheduler
Error 107 'WindowsApplication1.PatientSummaryForm' does not implement interface member 'WindowsApplication1.IBlur.UnBlur()' E:\c# projects\Eclipse\Scheduler\Oslerscheduler\OslerScheduler\PatientSummaryForm.Designer.cs 3 19 OslerScheduler
Can you tell me what I am doing wrong here?
VulpesPosted Sep 25, 2014, 5:40 PM
You then add an interface IBlur and make all forms implement this interface:
public interface IBlur
{
void Blur();
void UnBlur();
}
You can then add BlurAll and UnBlurAll methods (say) to Form1 which would now look like this:
public partial class Form1 : Form, IBlur
{
private PictureBox pb;
public Form1()
{
InitializeComponent();
pb = new PictureBox();
panel1.Controls.Add(pb);
pb.Dock = DockStyle.Fill;
}
public void Blur()
{
Bitmap bmp = Screenshot.TakeSnapshot(panel1);
BitmapFilter.GaussianBlur(bmp, 4);
pb.Image = bmp;
pb.BringToFront();
}
public void UnBlur()
{
pb.Image = null;
pb.SendToBack();
}
private void button1_Click(object sender, EventArgs e)
{
// open another form which has the Blur infrastructure already added
Form2 f2 = new Form2();
f2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
BlurAll();
MessageBox.Show("It's blurred now!");
UnBlurAll();
}
private void BlurAll()
{
foreach (Form f in Application.OpenForms)
{
((IBlur)f).Blur();
}
}
private void UnBlurAll()
{
foreach (Form f in Application.OpenForms)
{
((IBlur)f).UnBlur();
}
}
}