Natural_Demon
asked on
how to check if window is on top, window = hasfocus? - c# form application
i would like to set focus on a text field, when window(form) in on top of all on the desktop.
i have experimented with this ...
private void Form1_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
MessageBox.Show("Maximized ");
}
else if (this.WindowState == FormWindowState.Minimized)
{
MessageBox.Show("Minimized ");
}
if (ActiveForm == this)
{
MessageBox.Show("activated ");
textBox2.Focus();
}
}
but this code only shows ...
"MessageBox.Show("Minimize d");, window.
it only detects miinimized state, not the returning to maximiz state.
i would like to know how to detect if a form application is on top.
thank u.
i'm fairly a n oob in this materiaal.
c# vsX2008
kind regards
i have experimented with this ...
private void Form1_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
MessageBox.Show("Maximized
}
else if (this.WindowState == FormWindowState.Minimized)
{
MessageBox.Show("Minimized
}
if (ActiveForm == this)
{
MessageBox.Show("activated
textBox2.Focus();
}
}
but this code only shows ...
"MessageBox.Show("Minimize
it only detects miinimized state, not the returning to maximiz state.
i would like to know how to detect if a form application is on top.
thank u.
i'm fairly a n oob in this materiaal.
c# vsX2008
kind regards
ASKER
ok, and how to the detect the contrary?
if it's behind another program?
i have tested something like this after looking in google.
protected override void OnDeactivated(EventArgs e)
{
MessageBox.Show("hubabuba" );
}
this give error.
if it's behind another program?
i have tested something like this after looking in google.
protected override void OnDeactivated(EventArgs e)
{
MessageBox.Show("hubabuba"
}
this give error.
Thats a possible way that should work. What error do you get?
Regards,
Bruce
Regards,
Bruce
ASKER
Error 1
'WindowsFormsApplication1. Form1.OnDe activated( System.Eve ntArgs)':
no suitable method found to override formtest
: (
i found the keyword on msdn after u mentioned the other
'WindowsFormsApplication1.
no suitable method found to override formtest
: (
i found the keyword on msdn after u mentioned the other
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thnix, orks fine, and i tested a bit.
protected override void OnActivated(EventArgs e)
{
textBox3.Text = "hhhhi";
textBox3.Focus();
}
protected override void OnDeactivate(EventArgs e)
{
textBox3.Text = "";
}
Regards,
Bruce
Open in new window