Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:33:37+00:00 2026-06-02T22:33:37+00:00

Im trying to make my NSViews and windows that I create programmatically have a

  • 0

Im trying to make my NSViews and windows that I create programmatically have a fixed position no matter what the resolution of my screen is and no matter how many displays i have connected to my main desktop. For example if I have an external monitor or if I decide to change my screen resolution I want the NsRect of my NSView or NSWindow to always appear in the same place. Would this work?

NSRect mainFrame = [[NSScreen mainScreen] frame]
NSRect helpFrame = NSZeroRect;
helpFrame.origin.x = (mainFrame.size.width - width) / 2.0;

would that put the x value of my window always in the center no matter what the resolution is? I feel that when I connect an external monitor the resolution changes and the middle of the screen is no longer where I want it. Is NSScreen mainScreen the appropriate thing to call? thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:33:39+00:00Added an answer on June 2, 2026 at 10:33 pm

    First of all, what you’re asking is ambiguous. What does “same place” mean?

    You don’t show what width is. Assuming it’s the width of the window, what you showed will compute an X location that horizontally centers the window on the “main” screen. However, -mainScreen may not do what you think. If you want the primary display, the one with the menu bar, you want [[NSScreen screens] objectAtIndex:0].

    However, even if you set the window’s frame using the computation shown, that doesn’t keep it centered if the screen configuration changes. You need to observe the NSApplicationDidChangeScreenParametersNotification from the application object and recenter it.

    By the way, is there a reason you’re not using -[NSWindow center]?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make simple jQuery function to create a scrollToTop button that fades in
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a custom :confirm message for a rails form that returns data
Trying to make simple minesweeper game in python, but have one problem. I have
Trying to make a toggle button that hides/shows the right window/pane. Here is a
Trying to make iAds go off screen when no ad is loaded, as per
I have been trying to make my Mac application enter fullscreen now for a
Trying to make a regex that can handle input like either: Beverly Hills, CA
Trying to make a make generic select control that I can dynamically add elements
Right now I'm trying make some browser based game. But I have little questions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.