Windows center window on screen

Center Window on Screen

I’m creating a few screen casts and wanted to exactly center my windows in my screen. Any good way to do this on the Mac? I found an Apple Script example (and a few linked screens) but none of them support centering ‘Terminal’ vertically (although they do support centering other applications vertically).

6 Answers 6

I enjoy using SizeUp to manage windows, one of which is a center on screen option. Good luck.

Not sure if this might do what you are looking for as well, but Divvy is also a neat piece of software for arranging windows.

I suggest you watch the screencast on their website to see if it does what you are looking for, but basically it has a grid where you can change the size and position of the frontmost window.

You can also change the grid it displays to have finer control over the size of the windows you are working with.

Hope this helps.

Kevin. I’m the author of the post that you linked to on incrementalism.net.

The reason the Terminal window moves to the top is just a bug in Terminal’s AppleScript support.

This version does the vertical centering and works around the Terminal bug:

I hope that helps, if you haven’t already paid for one of the other options. I also added a comment with this workaround to the original post.

  • The bug with Terminal
  • Weird process names (firefox-bin)
  • Sizes of menu bar and Dock
  • Applescript support disabled in Preview
  • Windows that are almost full width / height will be resized to full width / height
  • rounding as taught in school isn’t really needed
    • the default is rounding to nearest , which rounds .5 to the nearest even integer (e.g 22.5 to 22)
  • Really, mixedCase variable names even here?

Still, there’s a dozen more things that could go wrong. The Dock part isn’t really needed if you have hiding always turned on. (But if for example orientation = bottom, you might want to set dth to dth — 4.)

window.open to center of screen

I am using window.open to open a popup window like so:

I want this to be centered in the screen, but without having to use and merely enter whatever I need within onclick=»» . Can this be done?

4 Answers 4

But in the meantime while i decide when i want to update this answer, this fiddle accounts for dual monitor setups: http://jsfiddle.net/w665x/138/

Original Answer

This might work for you. Not confident in it being entirely cross-browser, but close;

Also you can try:

This code works perfectly:

This code uses jAplus script. It allows you to do this without writing JavaScript code. (http://japlus.simplit.it)

Not the answer you’re looking for? Browse other questions tagged javascript popupwindow window.open 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.

Читайте также:  Windows console pop3 client

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.

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.

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“.

How do I center a window onscreen in C#?

I need a way to center the current window. So for example, if a user pushes a button, I want the window to center itself onscreen. I know you can use the startposition property, but I cannot figure out a way to use that other than when the application first starts up. So how do I center the form on the screen?

Читайте также:  Риск заражения вирусом windows

12 Answers 12

Using the Property window

Select form → go to property window → select «start position» → select whatever the place you want.

Form form1 = new Form(); form1.StartPosition = FormStartPosition.CenterScreen; form1.ShowDialog();

Note: Do not directly call Form.CenterToScreen() from your code. Read here.

In Windows Forms:

That’s all you have to do.

If you want to center your windows during runtime use the code below, copy it into your application:

And finally call the method above to get it working:

Centering a form in runtime

1.Set following property of Form:
-> StartPosition : CenterScreen
-> WindowState: Normal

This will center the form at runtime but if form size is bigger then expected, do second step.

2. Add Custom Size after InitializeComponent();

Centers any window you can get the handle of

Use Location property of the form. Set it to the desired top left point

desired x = (desktop_width — form_witdh)/2

desired y = (desktop_height — from_height)/2

Might not be completely relevant to the question. But maybe can help someone.

Center Screen non of the above work for me. Reason was I was adding controls dynamically to the form. Technically when it centered it was correct , based on the form before adding the controls.

So here was my solution. ( Should work with both scenarios )

So you will notice that I am using «PreferredSize» instead of just using Height / Width. The preferred size will hold the value of the form after adding the controls. Where Height / Width won’t.

Windows center window on screen

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

Answered by:

Question

the GetDesktopWindow() give us the screen HWND.

i need put the window in center of screen, but these code ins’t correct:(

Answers

I can’t make sense of the logic of your last code snippet, but perhaps it would be helpful if I posted some corrected code that does accurately center the console window:

All replies

i need put the window in center of screen, but these code ins’t correct:(

Why did you set the new width and height to 0?

Isn’t this what you want:

SetWindowPos(hwnwindow,HWND_NOTOPMOST, ConsolePosX,ConsolePosY,Width,Height, SWP_NOOWNERZORDER)?

Most of your code looks perfect for me, in SetWindowPos you need to add an parameter:

You can find the list of valid parameters here:

Only as an additional hint, if you also do not want to change the Z-Order this code would also be good:

Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

Most of your code looks perfect for me, in SetWindowPos you need to add an parameter:

You can find the list of valid parameters here:

Only as an additional hint, if you also do not want to change the Z-Order this code would also be good:

Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

Читайте также:  Кит кат лаунчер для windows phone

Brian.. the problem is that i can’t do 1000(for example) in width. the console window don’t accept.. only using the system() function(but use the character scale mode and not in pixels).

sorry but i need put the window in center of screen, but the GetDesktopWindow() function don’t recive the right results:(

i can’t put the window in center of screen(but allmost). please give me mor info.

Brian.. the problem is that i can’t do 1000(for example) in width. the console window don’t accept.. only using the system() function(but use the character scale mode and not in pixels).

sorry but i need put the window in center of screen, but the GetDesktopWindow() function don’t recive the right results:(

i can’t put the window in center of screen(but allmost). please give me mor info.

I just don’t follow your description. Can you put together a simple but complete application that demonstrates the problem? If so, load it on Skydrive so we can take a look at it.

Brian.. the problem is that i can’t do 1000(for example) in width. the console window don’t accept.. only using the system() function(but use the character scale mode and not in pixels).

sorry but i need put the window in center of screen, but the GetDesktopWindow() function don’t recive the right results:(

i can’t put the window in center of screen(but allmost). please give me mor info.

I just don’t follow your description. Can you put together a simple but complete application that demonstrates the problem? If so, load it on Skydrive so we can take a look at it.

do you want just the code?

(is because i use Visual C++ 6;))

heres the code. see that the width isn’t 1000 and isn’t in center of screen:(

Ah, it’s now clear to me what you are trying to do. I didn’t appreciate that the window you were trying to move and resize is a console window.

The fact is when SetWindowPos() is called, a combination of the WM_MOVE and WM_SIZE messages is sent to the target window. The target application may decide to act on this information and overrule what has happened, that is, decide that the size is too big, or wrong, and make another call to SetWindowPos() to correct the size and position.

I’m pretty confident this is probably what the console window is doing. Notice when you launch a console window manually that you can shrink the width of the window, but you can’t make the window any larger than the default.

Ah, it’s now clear to me what you are trying to do. I didn’t appreciate that the window you were trying to move and resize is a console window.

The fact is when SetWindowPos() is called, a combination of the WM_MOVE and WM_SIZE messages is sent to the target window. The target application may decide to act on this information and overrule what has happened, that is, decide that the size is too big, or wrong, and make another call to SetWindowPos() to correct the size and position.

I’m pretty confident this is probably what the console window is doing. Notice when you launch a console window manually that you can shrink the width of the window, but you can’t make the window any larger than the default.

only using system()(but use character instead pixel scale mode) function from stdlib library;)

i can resize the window, my problem now is: how can i put the console window on center of screen?

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