I have a Form that shows a Notification Window. But I want to show the popup only when the Form doesn't have focus or is not active, something like this:
if (!form.Active)
{
//Do something
}
Is there a way to do it?
Threading; // probably not required namespace AppName { public partial class Form1 : Form { protected override void OnActivated(EventArgs e) { Console. WriteLine("Form activated"); } protected override void OnDeactivate(EventArgs e) { Console. WriteLine("Form deactivated"); } // more program etc. } }
To determine whether the control has focus, regardless of whether any of its child controls have focus, use the Focused property. To give a control the input focus, use the Focus or Select methods.
Active Form In active sentences, the thing doing the action is the subject of the sentence and the thing receiving the action is the object. Most sentences are active.
if (Form.ActiveForm != yourform)
{
//form not active
//do something
}
else
{
// form active
// do something
}
This may help you on your quest. If your form is active, it'll tell you. If you click off the form, it'll tell you too.
using System;
using System.Text; // probably not required
using System.Windows.Forms; // probably not required
using System.Threading; // probably not required
namespace AppName
{
public partial class Form1 : Form
{
protected override void OnActivated(EventArgs e)
{
Console.WriteLine("Form activated");
}
protected override void OnDeactivate(EventArgs e)
{
Console.WriteLine("Form deactivated");
}
// more program etc.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With