Windows bring all to front

Windows bring all to front

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

With a Windows Forms form i call: this.BringToFront()
Whats the equivalent in WPF?

Thank you, regards

Answers

is this what you are looking for?

All replies

is this what you are looking for?

Topmost is equivalent to «Always On Top», which is not the same is BringToFront.

Calling this.Focus() will bring the window to the top, if it’s not already in focus.

I can’t get an existing window to come to the front, using any of the suggestions (3.5sp1)

When the modeless window is initially created, I set Topmost to true, and then set it back to false after the window is rendered. That seems to work as far as getting the window to initially show over its owner, and to not retain the Topmost behavior.

Another variable is setting the Owner property on the modeless window when it is created. (This is required if you want CenterOwner to work for a startup location). I find that when the window has an Onwer set, it gives something very much like Topmost behavior — the modeless window is always on top of its owner. Not what I want.

Windows: Bring Off-Screen Window Back Onto Screen

By Mitch Bartlett 115 Comments

While using Microsoft Windows, I had a window that had somehow fallen completely off of my screen. Right-clicking the window in the Taskbar and selecting Maximize brought it back, but there was no way I could get the window restored to where I could move it around my screen with my mouse.

Luckily, there are a couple of ways to bring off-screen windows back to the desktop screen.

Fix 1 – Resolution Trick

Windows 10 & 8

  1. Start the problematic application.
  2. Right-click a blank area of the Desktop, then choose “Display settings“.
  3. Select “Advanced display settings” at the bottom of the window.
  4. Temporarily change the “Resolution” to another value, then choose “Apply“.
  5. See if you can see the window on your screen now.
  6. Change the resolution back to the previous value, then select “OK“.

Windows 7

  1. Start the problematic application.
  2. Right-click a blank area of the Desktop, then choose “Screen Resolution“.
  3. Temporarily change the “Resolution” to another value, then choose “Apply“.
  4. See if you can see the window on your screen now.
  5. Change the resolution back to the previous value, then select “OK“.

Fix 2 – Show Desktop Toggle

  1. Hold down the Windows Key, then press “D“. Repeat these steps to see if it makes the window you are looking for reappear.
  2. Alternately, you can right-click a blank area of the taskbar, then choose “Show the desktop“, then repeat.
Читайте также:  How to check operative memory linux

Fix 3 – Move Option 1

  1. Select the program in the task bar.
  2. Hold the Windows Key while pressing Left Arrow or Right Arrow repeatedly to move the window back into view.

Fix 4 – Move Option 2

  1. In Windows 10, 8, 7, and Vista, hold down the “Shift” key while right-clicking the program in the taskbar, then select “Move“. In Windows XP, right-click the item in the task-bar and select “Move“. In some instances, you may have to select “Restore“, then go back and select “Move“.
  2. Use your mouse or the arrow keys on your keyboard to move the window back onto the screen.

Fix 5 – Cascade Windows

  • Right-click a blank area of the task-bar, then select “Cascade windows“.

Fix 6 – Maximize

Sometimes a single app will get stuck in a state where it cannot redraw onto the Window. You can usually alleviate this by doing the following.

  • Hold “Shift” and right-click on the program icon in the taskbar, then choose “Maximize“.

How do I prevent my application from starting off the screen every time I launch it?

Most applications will stop doing this if you properly exit out of the application while it is on the screen. If you have already properly exited the application, you might need to uninstall and reinstall it.

Otherwise, you can try right-clicking the icon for the application, then choosing “Properties“. Under the “Shortcut” tab, change the “Run” setting to “Maximized“, then select “OK“.

Bring Winforms control to front

Are there any other methods of bringing a control to the front other than control.BringToFront() ?

I have series of labels on a user control and when I try to bring one of them to front it is not working. I have even looped through all the controls and sent them all the back except for the one I am interested in and it doesn’t change a thing.

Here is the method where a label is added to the user control

Here is the method that sends all of them to the back.

5 Answers 5

Yeah, there’s another way. The Controls.SetChildIndex() also changes Z-order. The one with index 0 is the one on top. Doesn’t buy you anything though, BringToFront() uses this method.

Your SendLabelsToBack() method as given cannot work, it will also send the label to added to the back. But your next statement fixes that again.

Okay, that doesn’t work, which means the BringToFront() method doesn’t get executed. Look in the Output window for a «first chance exception» notification. As written, your SendLabelsToBack() will cause an exception if the user control contains any control other than a UserLabel. Also, set a breakpoint after the BringToFront() call and check the value of userContainer.Controls[0].Name when it breaks.

Controls’ z-index is per-container.

If you call BringToFront on a control that is inside a container (such as a Panel ), it will not bring the container to the front.
Therefore, the control will only go in front of other controls in that container.

Читайте также:  Internet explorer windows 10 enterprise

To see what containers your controls are in, you can use the Document Outline pane in the View menu.

EDIT: Your userContainer control is probably behind a different control.

Have you tried Invalidate() after BringToFront() ? BringToFront does not raise the Paint event

I think you just need to change your last line:

When you use a string as the indexer for the Controls collection, it goes by the Name property of the control (not the FieldName property).

Since you’re just trying to bring the most recently-added control to the top, this would also work:

From my experience looks like windows puts all controls belonging to one graphic container(pane, group box. etc) in a software collection. The collection is ordered by child index which is a property of every control in that container. The trick is that children with the same index can and do exists. In this case windows will paint those children ordered relative to others but between them it will paint them in the reverse order they had been added to the container.

Long story short: for one container-you need to make sure controls have different indexes by changing ALL NOT just SOME of the indexes when you want to change the z-order. For example:

where indexLogic(newControl ) is your method of calculation of the index of particular control.

Not the answer you’re looking for? Browse other questions tagged c# winforms controls or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

How can I bring my application window to the front? [duplicate]

How to bring my application window to front? For example whan my app needs attention.

This is for my personal program. I need that functionality.

This is what I got. But it’s NOT working 100% times.

And I call them from background worker.

And after pressing «Accept» button bool ready is set to true.

I works great but not always.

7 Answers 7

Here is a piece of code that worked for me

It always brings the desired window to the front of all the others.

Use Form.Activate() or Form.Focus() methods.

While I agree with everyone, this is no-nice behavior, here is code:

Update

David is completely right, for completeness I include the list of conditions that must apply for this to work (+1 for David!):

  • The process is the foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The foreground process is being debugged.
  • The foreground is not locked (see LockSetForegroundWindow).
  • The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
  • No menus are active.

How to bring a window to the front?

We have a Java application that needs to be brought to the foreground when a telecontrol mechanism activates something in the application.

Читайте также:  Bootcamp загрузка по поддержки windows зависает

In order to get this, we have realized in the called method of the class which represents the frame of our application (extension of a JFrame ) following implementation:

Under Windows XP, this works the first time it is called, on the second time only the tab in the taskbar flashes, the frame doesn’t come to the front anymore. Same goes for Win2k. On Vista it seems to work fine.

Do you have any ideas?

11 Answers 11

A possible solution is:

I had the same problem with bringing a JFrame to the front under Ubuntu (Java 1.6.0_10). And the only way I could resolve it is by providing a WindowListener . Specifically, I had to set my JFrame to always stay on top whenever toFront() is invoked, and provide windowDeactivated event handler to setAlwaysOnTop(false) .

So, here is the code that could be placed into a base JFrame , which is used to derive all application frames.

Whenever your frame should be displayed or brought to front call frame.setVisible(true) .

Since I moved to Ubuntu 9.04 there seems to be no need in having a WindowListener for invoking super.setAlwaysOnTop(false) — as can be observed; this code was moved to the methods toFront() and setVisible() .

Please note that method setVisible() should always be invoked on EDT.

Windows has the facility to prevent windows from stealing focus; instead it flashes the taskbar icon. In XP it’s on by default (the only place I’ve seen to change it is using TweakUI, but there is a registry setting somewhere). In Vista they may have changed the default and/or exposed it as a user accessible setting with the out-of-the-box UI.

Preventing windows from forcing themselves to the front and taking focus is a feature since Windows 2K (and I, for one, am thankful for it).

That said, I have a little Java app I use to remind me to record my activities while working, and it makes itself the active window every 30 minutes (configurable, of course). It always works consistently under Windows XP and never flashes the title bar window. It uses the following code, called in the UI thread as a result of a timer event firing:

(the first line restores if minimized. actually it would restore it if maximized too, but I never have it so).

While I usually have this app minimized, quite often it’s simply behind my text editor. And, like I said, it always works.

I do have an idea on what your problem could be — perhaps you have a race condition with the setVisible() call. toFront() may not be valid unless the window is actually displayed when it is called; I have had this problem with requestFocus() before. You may need to put the toFront() call in a UI listener on a window activated event.

2014-09-07: At some point in time the above code stopped working, perhaps at Java 6 or 7. After some investigation and experimentation I had to update the code to override the window’s toFront method do this (in conjunction with modified code from what is above):

As of Java 8_20, this code seems to be working fine.

Оцените статью