This question already has an answer here:
Application 'Deactivate' event
(1 answer)
Closed 8 years ago.
I want to create an application that closes one of it's window when the user clicks on another application (or in other words the application loses focus or inactive). All the windows in my application to have the property TopMost = true.
How I can do that?
your help is greatly appreciated.
Edit (Update):
I need when I click on another window in my application, the window is not closed. Only when my application loses focus (the user clicks on another application), the window will be closed.
Check out the Deactivate event, or override OnDeactivate:
protected override void OnDeactivate(EventArgs e)
{
Close();
}
Related
This question already has answers here:
C# - Add button click events using code
(3 answers)
Closed 3 years ago.
I very new to C# and I would like to add a Button to a form programmatically. When this button is pressed I want it to run some code (like a normal button woukd work). But, everywhere I have searched only shows how to add the button and not how to add code to the button.
One way to do it is to give the button a name property, then in your code you "refer" to the button by it's name like so:
void btnButton_Click(object sender, EventArgs e)
{
// your code goes here
}
where btnButton_Click is the name of the button.
This question already has answers here:
How to enable button in Form 1 from Form 2 using public get set?
(5 answers)
Closed 4 years ago.
I want to disable the button from other form from current form and enable the button again after clicking reset button.
Add a public method where you control the button state as disabled or enabled in this form,then transfer this form as parameter to other form
This question already has answers here:
Show a Form without stealing focus?
(19 answers)
Closed 6 years ago.
I have a sort of a pop-up windows form. It pops up to show gathered data. Problem is it gains focus when it loads and interrupts work. I need it not to get focus when loaded. How to do that?
the Simplest thing you can do is, first load all the data which you gathered and when u feel its ready and you want to load the popup window, call the
window.show()
this will help you to use the data once its loaded. Also it would be better if you can share more details on the same.
In Your form class, override OnLostFocus(EventArgs e) and place a focusing call inside it. So it looks like this:
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.Focus();
}
Sometimes if that doesn't work try:
protected override void OnDeactivate(EventArgs e)
{
base.OnDeactivate(e);
this.Focus();
}
This question already has answers here:
Why does modal-form disappear completely when minimized?
(5 answers)
Closed 7 years ago.
I have problem with minimizing by program. It has main form and others, which I open by ShowDialog()
Problem is with minimizing these dialog forms. When my friend on Windows7 minimize this dialog, it minimize dialog and main form (dialog isn't in taskbar, I disabled it), but on my Windows7 only dialog is minimized like this
Is here any chance to minimize both forms? I found, that after form is minimized, Resize event is fired, so I made this
private void ShowCode_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
main.WindowState = FormWindowState.Minimized;
}
}
but when I click on form in taskbar, main form is showed and dialog is closed, I don't know why?
Is here any chance, to always minimize it to taskbar?
And why on my PC it works this way, and on friend's other way? I don't know that I changed something in Windows settings.
If I understand you correctly - I found a solution after asking a similar question.
Simply add a: Show();
At the end of Form2's event-handler.
See about it here (and in the other answers.)
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
(C#) How to detect when a windows form is being minimized
First of all my code:
private void Form1_Load(object sender, EventArgs e)
{
this.MinimumSizeChanged += new EventHandler(Form1_MinimumSizeChanged);
}
void Form1_MinimumSizeChanged(object sender, EventArgs e)
{
MessageBox.Show("1");
}
so, my program idea is, when the program get minized i will do a system tray, but this event never happnd. how can i know when the user do a minize screen(minize the program).
i have tryed everything. any ideas?
MinimumSizeChanged has nothing to do with the form getting minimized. MinimumSizeChanged has to deal with when the MinimumSize properties of the form are changed.
You want to check the Resize event of the form.
In order to minimize to the system tray, add a NotifyIcon control to your form. Now, override the OnResize method and check if your WindowState property is set to FormWindowState.Minimized. If it is, Hide() your forms and show your notify icon. Make sure to set the Icon property of the NotifyIcon as well. Now just reverse the process for the case when the form is restored.