WPF window can't be restored from the taskbar or using Alt+Tab after being minimized (it stays minimized). It happens on a part of environments (on my machine it's Ok but fails on some others).
I can switch to the window from Task manager - then it gets restored.
As a hotfix I added:
void Window_Activated(object sender, EventArgs e)
{
...
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;
}
}
It helped. But I don't think that is the best solution. Have you any other ideas to fix it?
Seems the best existing solution so far is the one I found:
void Window_Activated(object sender, EventArgs e)
{
...
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;
}
}
Related
I've been looking around and cant seem to find any of the help I need for my program
I need it so when I click a specific button(F9) It hides the program from taskbar. After its hidden from taskbar I need to be able to click a button(F10) to make it Show in task bar again. Currently when I run it F9 Hides it but F10 wont show it
private void Menu_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F9)
{
SecHiden.PerformClick();
}
if (e.KeyCode == Keys.F10)
{
SecShow.PerformClick();
}
}
private void SecHiden_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
private void SecShow_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
}
}
EDIT: i've figured out the error just need help fixing it
I have to be tabbed into the program for the Keybinds to work is there a way to fix this? I would like to able to use the keybinds when im on Any specift tab(F10 Wouldnt show the tab because I wasnt tabbed onto the program to make the keybind work)
I am developing a little applicacion, using Visual Studio 2022, together with .NET 6.0
I have a MainWindow and attached a subordinate Window which I am showing as follows:
private void s_Betrieb_Click(object sender, RoutedEventArgs e)
{
BetriebWindow betriebWindow = new();
betriebWindow.Owner=this;
betriebWindow.Show();
}
The subordinate Window BetriebWindow is an ordinary Window, defined in XAML, whitch shows an input-Form (using textBoxes and labels).
After having changed some input, the user clicks on "Close" (the red x in the right upper edge of the Window). I am asking the user wheather he would like to save his changes or not, using a MessageBox.Show().
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Wollen Sie Ihre ",...) == MessageBoxResult.OK)
SaveData();
Close();
}
After the subordinate Window has closed, the MainWindow is minimizing itself and appears in the taskbar, which I (and perhaps even the future user) don't like.
What am I doing wrong? I want the MainWindow to remain opened on the screen.
But closing the MainWindow should close the subordinate window, too.
Thanks for an answer!
Paul
Remove the call to Close() in the Closing handler and call Activate() on the main window when the child window has been closed:
private void s_Betrieb_Click(object sender, RoutedEventArgs e)
{
BetriebWindow betriebWindow = new();
betriebWindow.Owner = this;
betriebWindow.Closed += (ss, ee) => Activate();
betriebWindow.Show();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Wollen Sie Ihre ", ...) == MessageBoxResult.OK)
SaveData();
}
This problem is happening when the FormBorderStyle = None and a button is used to set the WindowState. Chunks of the form turn invisible when the form is restored from a minimized state or is maximized from a normal state.
The code for maximizing and minimize:
private void MaximizeButton_Click(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Maximized;
}
else
{
WindowState = FormWindowState.Normal;
}
}
private void minimize_button_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
I have failed to recreate this glitch in any other winform based application of mine.
I appreciate the help , hope you all are having a comfortable covid stay.
Simply refresh the window once its state becomes maximized. Unlike WPF, Winforms doesn't have a StateChanged event, so use SizeChanged to detect if the window it's maximized, and refresh it.
private void Window_SizeChanged(object sender, EventArgs e)
{
if(WindowState == FormWindowState.Maximized)
Refresh();
}
I am trying to make my application minimize to task bar/tray
Here is my code so far that I have pulled together from other SO posts and other people seem to have it working but my app minimizes to the tray but when I click it in the tray it doesn't reopen.
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
just to explain again the problem is the application minimizes to the tray but when I click on the icon it doesn't restore the app to normal. Instead it does nothing.
I found my problem.
what I didn't do was this
Set the NotifyIcon's visible property to false in the property editor. Now go to the property editor of Form1, click on the little lightning symbol to access the events, and double click on the Resize event, and change the code to:
and I also didn't do this
Finally we need the code to make the program show up again when the icon is double clicked. So double click on NotifyIcon1 in the designer,
I found this information here
Dreamincode
This is what I have used in the past but I fund a copy online at the link below
if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
found here: http://www.codeproject.com/Articles/27599/Minimize-window-to-system-tray
I'm Currently Working in Windows Application.
I just created a tray Icon while closing the Form, Tray Icon is visible in System Tray.
While Left Click the Tray Icon Form is maximized to normal state.
Right Click Event is not working in Release Mode, but working in Debug Mode.
After Building this application Right Event is not working, the output.exe file from Debug mode.
Any help would be appreciated.
Thanks in Advance.
In form Load
private void MainRelease_Load(object sender, EventArgs e)
{
TrayIcon.Visible = false;
TrayMenu.Items.Add("Exit");
TrayMenu.Items[0].Click += new System.EventHandler(this.Dispose_Click);
}
In button close Event
private void btnClose_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
TrayIcon.Visible = true;
ShowInTaskbar = false;
}
In Tray Icon mouse click Event
private void TrayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.WindowState = FormWindowState.Normal;
TrayIcon.Visible = false;
ShowInTaskbar = true;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
TrayMenu.Show(Cursor.Position.X, Cursor.Position.Y);
}
}
Tray Menu dispose event
private void Dispose_Click(object Sender, EventArgs e)
{
TrayIcon.Visible = false;
TrayIcon.Icon = null;
TrayIcon.Dispose();
Application.Exit();
}
While in Release Mode Tray Icon Mouse Right Click Event is not working . But in Debug Mode its working.
Please Help me to solve this Issue.
Maybe this is a dumb answer, but are you sure your release build is up to date? If your debugging in the designer then the release build isn't updated when you run a Build unless you set it up that way. Maybe your release build is from before you added code to handle the right click?
If its not that, does the release build work if you run it from the Release folder rather than debugging in release mode from the designer?