Window Flicker on loss of focus? - c#

I have been working on a windows form application based in c# and I am in need of some assistance. I am trying to recreate the window flicker that most windows applications have when a form loses focus to a parent form. Best way I can explain this is open up calculator open the help window and try to click the calculator, the help window then without falling behind the calculator flickers losing and gaining the shadowing around the edges.
I have managed to regain the focus on the child window when the parent is clicked but this creates a odd flickering effect as the parent window is momentarily brought in front of the child window. I am only guessing but that effect I am looking for appears to be that the calculator is never brought in front of the help window and then the help window is simply activated and deactivated a few times.
I tried doing some searches and I have seen a few topics relating to this but none of the solutions quite match. I am fairly new to making windows form applications so there are still a things I don't understand so be patient with me if I don't understand something at first.
Thank you in advance
An elaboration on the calculator example:
1) open up calculator from windows accessories
2) in the toolbar go to the help tab and open the about calculator option
3) click on the calculator window
4) the about calculator window will then flicker while never falling behind the calculator
The only progress I have made towards this is
private void MainForm_Activated(object sender, EventArgs e)
{
if (Open == true)
{
//blink active window
_addForm.Activate(); //makes window active
}
}
The open variable is something I use to keep track of if open forms and is made true when I show another form.

In your example the About window is called a modal window. A modal window prevents the user from interacting with the parent window until it is closed. Use Form.ShowDialog instead of Form.Show to present a Form to the user as a modal window.

Make the child form modal. This means that the child must be closed properly before focus can be transferred back to the parent.

Related

Show icon in taskbar for hidden windows

When I set the main window's visibility to hidden, No icon is shown in taskbar, so I have no control over the window to show it again. I want for the application's icon to be visible even when I hide the window, and to show the window when I click it's button in the taskbar. (something like minimize behavior)
How can I achieve that using WPF and .Net 4.0 in C#?
Edit: I mean the icon in taskbar (usually in the left and middle of the horizontal taskbar) not the notifyicon in system tray.
So, based on "comments" section, what you are looking to do is minimize or hide a window but still show some windows or dialogues that the window opens. First if you want to keep your window in the task bar, you should minimize with:
this.WindowState = WindowState.Minimized
That can be called from anywhere within the form. As you mentioned, though, this will close hide any dialogues that have this window set as the parent. The key, then is to not use this window as the parent. Lets say your dialogues inherit from form. You want to use:
newWindow.Show();
I am guessing that you are calling "ShowDialog", which ties the window state to the parent window state. Try this out and hopefully it will help!
Edit
One more note: the same is actually true of MessageBoxes, but the way to control the parent form is with the first parameter of the MessageBox.Show() call. If you pass in a form as the first parameter, that will be the parent, otherwise the parent will not be set.

"Tint" an entire window, or alternative method of making window look inactive

I have a winforms C# application that opens multiple dialog boxes. To suit the style of the application, I have removed the default title bars for each window and created my own (with control buttons and drag-to-move function).
The problem that now faces me is that without a titlebar, the user has no way of telling which window is the 'active' window when they are manually moved apart (so they are not overlapping).
In any windows application (that uses titlebars), when you try to navigate away from a dialog box back to the main program (without closing the dialog box) - it wont let you. The border of the dialog box flashes and you hear a windows error sound. Some kind of equivalent visual feedback would be great without needing to have the default titlebars - and tinting an entire window darker seems like it would do the trick nicely.
Something like this in pseudo-code, which would nicely tint the parent window whilst a dialog is open:
// tint window now
window.ShowDialog();
// un-tint window
I have tried to place a panel covering everything with colour set to 'transparent' (with the intention of later controlling the opacity of the panel) but the transparency does not seem to work. Any other ideas of accomplishing this? Or does anyone have a better suggestion to achieve the same level of visual feedback?
Summary:
Is there any way to tint an entire window, or overlay it with a colour? If not, could anyone suggest an alternate method of making the window appear 'inactive'?
I would suggest you to create a method in forms you want to disable:
void DisableForm()
{
//some fancy color
this.BackColor = System.Drawing.Color.Khaki;
//and disable all controls owned by form, just to be sure
foreach (var s in this.Controls)
{
((Control)s).Enabled = false;
}
}
and functions which enables back those forms of course.
edit.
also you can set visibility property of controls to false

Win api in C#. Parent window draws on its child

I have created a window in C# by win api. And made it as child to another window. This parent window is an external program and I don't know its source code.
When i move my window inside parent window some parent's elements draw itself on my window.
For, better understanding i've made some screens.
This is before I move my window. My window is gray.
And this one is after moving my window over the "SeatOpen" button.
I have no idea how parent window can draw on my window.
So, why this is happening and how to fix?
The parent window is not drawing on your window... you are failing to draw on your window yourself -- your window is not responding to WM_PAINT messages for some reason so whatever garbage was on the screen remains there.
Try to redraw your window when location is changed and it is over Seat Open button.

C# Fullscreen, hiding the taskbar

I have recently written an application for my daughter, which is a kid-free zone where she has all unnecessary key presses ignored (windows key, Esc etc) but the problem I am having is that when I use the following code:
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
I am able to HIDE the taskbar, but it is not truly overlayed. When I move the mouse to where the taskbar would be, and click, it pops up, also, using this code and running external applications withing my windows form, I am left with this windows form keeping itself on top.
If anyone could help me with a proper way to display my windows form as a true fullscreen application, and be able to run external applications from within the form and have them prioritize themselves on top, that would be greatly appreciated.
In case you missed it, I am using VS2010, C# and winforms.
Thanks in advance!
The proper way to make a full-screen app is to just put something like Bounds = Screen.PrimaryScreen.Bounds; in your main form. Then when your app has focus it will cover the task bar.
You also probably want FormBorderStyle = FormBorderStyle.None;
The order of the performed actions is incorrect.
You should first hide the border (FormBorderStyle=None), and then set the window state to maximized. You even don't have to set TopMost to true.

WPF-Window Topmost for own application only?

The Splashscreen/Loading-Window in my WPF application is set to Topmost="True". Now this windows in on top of all other windows even when you switch to another application (because loading will take some time). I don't want this kind of behavior.
If I set Topmost="False" the window in not topmost at all. But If you switch back to my application after working with with another application my customers sometimes don't realize the Loading-Windows is still working. The application appears to be unresponsive because the Loading-Window in the background is still the active window and it is modal.
I want to have the Loading-Window topmost but only if my application is in foreground. If you switch to another program the window should disappear and reappear topmost when you switch back.
You can try to use the "Owner" property of the window, with that the splash screen will always overlap the other windows.
I think maybe a change in the loading pattern of your MainWindow might help. If you can put to time consuming part of loading the window on a background thread then you can take this path:
Show MainWindow empty or bare bones (empty fields/grid etc)
Launch async load method to get data and populate main window
Create splash screen, set owner to self and show
make sure to close splash screen when load is complete.
that should keep the splash on top while load is being processed.
To clarify I will reanswer this question:
Martin Moser's answer is the correct one.
Set the owner property like:
secondarywindow.Owner = parent;
AND set TopMost to false.

Categories