Windows forms window on top

Form. Top Level Свойство

Определение

Возвращает или задает значение, определяющее режим отображения формы в качестве окна верхнего уровня. Gets or sets a value indicating whether to display the form as a top-level window.

Значение свойства

true для отображения формы в качестве окна верхнего уровня; в противном случае — false . true to display the form as a top-level window; otherwise, false . Значение по умолчанию — true . The default is true .

Исключения

Необходимо, чтобы родительская MDI-форма являлась окном верхнего уровня. A Multiple-document interface (MDI) parent form must be a top-level window.

Примеры

В следующем примере свойство используется Modal для определения, отображается ли форма как модальная форма. The following example use the Modal property to determine if a form is displayed as a modal form. Если это не так, FormBorderStyle TopLevel Свойства и изменяются, чтобы форма не стала формой верхнего уровня с границей окна инструментов. If it is not the FormBorderStyle and TopLevel properties are changed to make the form non-top-level form with a tool window border.

Комментарии

Форма верхнего уровня — это окно, не имеющее родительской формы или родительской формы которого является окном рабочего стола. A top-level form is a window that has no parent form, or whose parent form is the desktop window. Окна верхнего уровня обычно используются в качестве основной формы в приложении. Top-level windows are typically used as the main form in an application.

How to make a window always stay on top in .Net?

I have a C# winforms app that runs a macro in another program. The other program will continually pop up windows and generally make things look, for lack of a better word, crazy. I want to implement a cancel button that will stop the process from running, but I cannot seem to get the window to stay on top. How do I do this in C#?

Edit: I have tried TopMost=true; , but the other program keeps popping up its own windows over top. Is there a way to send my window to the top every n milliseconds?

Edit: The way I solved this was by adding a system tray icon that will cancel the process by double-clicking on it. The system tray icon does no get covered up. Thank you to all who responded. I read the article on why there is not a ‘super-on-top’ window. it logically does not work.

13 Answers 13

Form.TopMost will work unless the other program is creating topmost windows.

There is no way to create a window that is not covered by new topmost windows of another process. Raymond Chen explained why.

I was searching to make my WinForms application «Always on Top» but setting «TopMost» did not do anything for me. I knew it was possible because WinAmp does this (along with a host of other applications).

What I did was make a call to «user32.dll.» I had no qualms about doing so and it works great. It’s an option, anyway.

First, import the following namespace:

Add a few variables to your class declaration:

Add prototype for user32.dll function:

Then in your code (I added the call in Form_Load()), add the call:

Hope that helps. Reference

If by «going crazy» you mean that each window keeps stealing focus from the other, TopMost will not solve the problem.

Читайте также:  Таймер выключения компа windows 10

This will show the ‘child’ form without it stealing focus. The child form will also stay on top of its parent even if the parent is activated or focused. This code only works easily if you’ve created an instance of the child form from within the owner form. Otherwise, you might have to set the owner using the API.

I had a momentary 5 minute lapse and I forgot to specify the form in full like this:

But what I really wanted was THIS!

Set the form’s .TopMost property to true.

You probably don’t want to leave it this way all the time: set it when your external process starts and put it back when it finishes.

The way i solved this was by making a system tray icon that had a cancel option.

The following code makes the window always stay on top as well as make it frameless.

What is the other application you are trying to suppress the visibility of? Have you investigated other ways of achieving your desired effect? Please do so before subjecting your users to such rogue behaviour as you are describing: what you are trying to do sound rather like what certain naughty sites do with browser windows.

At least try to adhere to the rule of Least Surprise. Users expect to be able to determine the z-order of most applications themselves. You don’t know what is most important to them, so if you change anything, you should focus on pushing the other application behind everything rather than promoting your own.

This is of course trickier, since Windows doesn’t have a particularly sophisticated window manager. Two approaches suggest themselves:

  1. enumerating top-level windows and checking which process they belong to, dropping their z-order if so. (I’m not sure if there are framework methods for these WinAPI functions.)
  2. Fiddling with child process permissions to prevent it from accessing the desktop. but I wouldn’t try this until the othe approach failed, as the child process might end up in a zombie state while requiring user interaction.

Form. Top Most Свойство

Определение

Возвращает или задает значение, указывающее, отображать ли форму как форму переднего плана. Gets or sets a value indicating whether the form should be displayed as a topmost form.

Значение свойства

Значение true для отображения формы как формы переднего плана; в противном случае — значение false . true to display the form as a topmost form; otherwise, false . Значение по умолчанию — false . The default is false .

Примеры

В следующем примере демонстрируется создание самой верхней формы. The following example demonstrates how to create a topmost form. В примере создаются две формы, одна из которых развернута, а другая — как самая верхняя форма. The example creates two forms, one that is maximized and one that will be displayed as a topmost form. Первая форма с именем bottomForm отображается в развернутом виде с помощью WindowState свойства, чтобы лучше продемонстрировать возможности самой верхней формы. The first form, named bottomForm , is displayed maximized, using the WindowState property, to better demonstrate the abilities of the topmost form. Вторая форма с именем topMostForm задает TopMost свойство для, чтобы true отобразить форму в виде самой верхней формы. The second form, named topMostForm , sets the TopMost property to true to display the form as a topmost form. При выполнении этого кода щелчок развернутой формы не приведет к отображению самой верхней формы под развернутой формой. When this code is run, clicking on the maximized form will not cause the topmost form to be displayed below the maximized form. В этом примере требуется, чтобы метод, определенный в примере, вызывался из другой формы. The example requires that the method defined in the example is called from another form.

Читайте также:  Soothe vst mac os

Комментарии

Самая верхняя форма — это форма, которая пересекает все остальные (не самые верхние) формы, даже если она не является активной или основной формой. A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Самые верхние формы всегда отображаются в самой высокой точке z-порядка окон на рабочем столе. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop. Это свойство можно использовать для создания формы, которая всегда отображается в приложении, например в окне инструментов поиска и замены. You can use this property to create a form that is always displayed in your application, such as a Find and Replace tool window.

Make a window stay Always On Top in Windows 10

Do you like the Always On Top feature provided by some apps and want this feature in other apps too? Well, you can make any window stay at the top of other windows. This post discusses a number of tools that let you do so. Keeping a window on top comes with a lot of benefits, you can continue doing your work, while also keeping an eye on other windows as well.

Make a window stay Always On Top

Here are a few free tools that can help you achieve this on your Windows 10/8/7 PC:

  1. TurboTop
  2. OnTopReplica
  3. Always On Top
  4. DeskPins
  5. AOT Extension for Chrome & Firefox
  6. WindowTop
  7. PinWin
  8. PinWin – Pin On Top
  9. OnTopper
  10. PinMe
  11. Window TopMost Control
  12. TopMostFriend.

Let us take a look at them.

1] TurboTop

TurboTop is again a small utility that runs from the system tray. It lets you choose the window that you want to keep on top and that all. The window would stick to the top while you do your work. There are no hotkeys or customizations possible with this tool. TurboTop is very simple to use and just does what it says. Click here to download TurboTop.

2] OnTopReplica

OnTopReplica is a great tool that creates a real-time clone of a specified window using DWM Thumbnails and the Windows Forms Aero library. You can create a clone by selecting a Window or by specifying an area from your screen. You can easily resize the window as per your requirement and tweak a few other settings as well. You can set the clone opacity and even lock its position on the screen. To facilitate the task, you can even choose hotkeys to clone the screen and also for showing/hiding the cloned window. Click here to download OnTopReplica.

3] Always On Top

Always On Top is a small little utility that lets you keep any window in the foreground. You just need to download the application, run it and press the hotkey. Always On Top does not feature any other imaging functionalities as such but still the tool makes it easier to keep windows on top. It makes the entire task a lot easier and faster. All you need to do is select the window and then hit ‘Ctrl + Space’ from your keyboard, and the window will stay there as it is on top of all other windows. Click here to download Always On Top.

4] DeskPins

DeskPins is another lightweight tool that can force any running programs to stay on top of others. It is available here.

5] AOT Extension for Chrome & Firefox

AOT a.k.a. Always on Top extension for Google Chrome lets you keep any webpage on top of all other windows. The extension comes handy when you are manually doing some data entry on a webpage and minimizing and then maximizing windows is a pain. To use the extension you need to enable Panels from ‘chrome://flags’. To set a webpage on top you just need to open the webpage in Google Chrome, then right-click and then select ‘Always On Top’. The webpage will be opened in a new customized window that would always stay on top. Click here to download AOT Chrome Extension. A similar extension is also available for Mozilla Firefox that can be downloaded from here.

Читайте также:  Какие шрифты лучше linux

UPDATE: The Chrome Extension AOT has been discontinued. It is still available for Firefox.

6] WindowTop

You might want also to check out WindowTop. It is a free utility for Windows that lets you pin an open window on top of others. You can control opacity, click-through windows, enable Dark Mode & Shrink the open applications.

7] PinWin

PinWin is a very simple and intuitive app that allows you to make any 3rd party window, remain “always-on-top”. It will appear on top of other windows at all times. Available here.

8] PinWin – Pin On Top

PinWin – Pin On Top is another minimal Windows system tray application that allows you to pin any windows to the top of the screen with one click. Available here.

9] OnTopper

OnTopper is another free tool available on SourceForge that lets you pin a program window topmost.

10] PinMe

PinMe lets you pin a window Always On Top, change transparency level, capture windows, and offer basic statistics on your PC.

11] Window TopMost Control

TopMost Control can make any program window stick over other program windows. To make a window always on Top you have four options:

  • Select a window and double click to the TopMost Control icon in the system tray
  • Select a window and use Ctrl+Alt+Space Keyboard shortcuts
  • Use Windows List in system tray menu
  • Use CMD.

12] TopMostFriend

This free utility lets you quickly force any program to be always on top. It should work on any version of Windows that supports .NET Framework 4.0 and is available for download from Github.

Control. Top Свойство

Определение

Возвращает или задает расстояние в пикселях между верхней границей элемента управления и верхней границей клиентской области его контейнера. Gets or sets the distance, in pixels, between the top edge of the control and the top edge of its container’s client area.

Значение свойства

Объект Int32, представляющий расстояние (в пикселях) между нижней границей элемента управления и верхней границей клиентской области контейнера. An Int32 representing the distance, in pixels, between the bottom edge of the control and the top edge of its container’s client area.

Примеры

Следующий пример кода создает три Button элемента управления в форме и задает их размер и расположение с помощью различных свойств, связанных с размером и расположением. The following code example creates three Button controls on a form and sets their size and location by using the various size-related and location-related properties. В этом примере предполагается, что у вас есть Form Ширина и высота не менее 300 пикселей. This example requires that you have a Form that has a width and height of at least 300 pixels.

Комментарии

TopЗначение свойства эквивалентно Point.Y свойству Location значения свойства элемента управления. The Top property value is equivalent to the Point.Y property of the Location property value of the control.

Изменения, вносимые в Height Top значения свойств и, приводят к Bottom изменению значения свойства элемента управления. Changes made to the Height and Top property values cause the Bottom property value of the control to change.

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