This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Window. Location Changed Event
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when the window's location changes.
A window's location changes when:
A user moves a window by dragging it with the window's title bar.
A window is moved after DragMove is called.
Either the Left or Top property is set programmatically.
The Move menu item of a window's System menu is chosen.
The WindowState property is changed.
- RestoreBounds
Additional resources
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Which event captures position change of a Window?
I need some event like the SizeChanged on MainWindow that is activated when the user has changed the position of a window?
Many Thanks,
- 1 Doh. So obvious. I was keep looking for Position instead of location :)) – Houman Jun 8, 2011 at 14:57
5 Answers 5
I think it is the LocationChanged event .
LocationChanged?
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.locationchanged.aspx

I believe that .LocationChanged is the event you are looking for.

How to Find an Event - A Visual Studio Adventure

You can even try RegionChanged event which is similar to LocationChanged
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged c# .net wpf events window or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
Hot Network Questions
- Does Counterspell prevent from any further spells being cast on a given turn?
- Do new devs get fired if they can't solve a certain bug?
- Why are physically impossible and logically impossible concepts considered separate in terms of probability?
- About an argument in Famine, Affluence and Morality
- What is the correct way to screw wall and ceiling drywalls?
- Is it correct to use "the" before "materials used in making buildings are"?
- Did any DOS compatibility layers exist for any UNIX-like systems before DOS started to become outmoded?
- Time arrow with "current position" evolving with overlay number
- Theoretically Correct vs Practical Notation
- Minimising the environmental effects of my dyson brain
- Coasting Along the Coast
- What is pictured in this SHERLOC camera?
- Stored Procedure Tuning Help
- Bulk update symbol size units from mm to map units in rule-based symbology
- What did Ctrl+NumLock do?
- How do particle accelerators like the LHC bend beams of particles?
- Follow Up: struct sockaddr storage initialization by network format-string
- What is a word for the arcane equivalent of a monastery? A place where magic is studied and practiced?
- Copyright issues when journal is defunct
- Any idea what set any of these are from? mostly minifigs and decorated bricks
- Calculate the inscribed circle between 1 line and 2 cirlces
- Can I tell police to wait and call a lawyer when served with a search warrant?
- What is the purpose of this D-shaped ring at the base of the tongue on my hiking boots?
- Do I need a thermal expansion tank if I already have a pressure tank?
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

- Latest Articles
- Top Articles
- Posting/Update Guidelines
- Article Help Forum

- View Unanswered Questions
- View All Questions
- View C# questions
- View Python questions
- View Javascript questions
- View C++ questions
- View Java questions
- CodeProject.AI Server
- All Message Boards...
- Running a Business
- Sales / Marketing
- Collaboration / Beta Testing
- Work Issues
- Design and Architecture
- Artificial Intelligence
- Internet of Things
- ATL / WTL / STL
- Managed C++/CLI
- Objective-C and Swift
- System Admin
- Hosting and Servers
- Linux Programming
- .NET (Core and Framework)
- Visual Basic
- Web Development
- Site Bugs / Suggestions
- Spam and Abuse Watch
- Competitions
- The Insider Newsletter
- The Daily Build Newsletter
- Newsletter archive
- CodeProject Stuff
- Most Valuable Professionals
- The Lounge
- The CodeProject Blog
- Where I Am: Member Photos
- The Insider News
- The Weird & The Wonderful
- What is 'CodeProject'?
- General FAQ
- Ask a Question
- Bugs and Suggestions

Window Location in WPF

- Download demo - 73.58 KB
- Download source - 160.95 KB

Introduction
This is a simple application that shows how we can change window location in WPF. This robot follows your cursor forever.
Using the Code
In a few steps, we can create this application. First I created a window in WPF - I've done it with Expression Blend 2 SP1.
Then we can access the window location with these properties:
I've added some methods to use cursor position for changing the window location:
That's all.
- 13 th December, 2008: First post
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Comments and Discussions
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
WPF | Help Topics
Handle window state changing events.
There are two events associated when the dialog window’s state changes. These events have the suffix “ing” or “ed” appended to them, reflecting the order in which they occur. The window state changing events allow you to perform some custom business logic before or after the window’s state is changed.
WindowStateChanging - The moment right before the dialog window control’s state changes, the WindowStateChanging event fires. You can cancel this event if certain conditions are not met.
WindowStateChanged -This event fires after the dialog window control’s state is changed.
The following code demonstrates how to handle the WindowStateChanging and WindowStateChanged events.
In Visual Basic:
Related Topics
Custom Cursors
Customize Modal Dialog Window Background
Customize the Window Header Icon
Handle Moving Events
Keyboard Settings
Modal and Modeless Dialog Windows
Position Minimized Dialog Window
Set the Dialog Window’s Height and Width When Minimized
Start Up Position of xamDialogWindow
The xamDialogWindow Control’s Behavior
Window Header Controls
# window.location Cheatsheet
Looking for a site's URL information, then the window.location object is for you! Use its properties to get information on the current page address or use its methods to do some page redirect or refresh 💫
https://www.samanthaming.com/tidbits/?filter=JS#2
- Difference between host vs hostname
- How to change URL properties
- window.location vs location
- window.location.toString
- assign vs replace
- replace vs assign vs href
- Scratch your own itch 👍
- Community Input
# window.location Properties
# difference between host vs hostname.
In my above example, you will notice that host and hostname returns the value. So why do these properties. Well, it has do with the port number. Let's take a look.
URL without Port
https://www.samanthaming.com
URL with Port
https://www.samanthaming.com:8080
So host will include the port number, whereas hostname will only return the host name.
# How to change URL properties
Not only can you call these location properties to retrieve the URL information. You can use it to set new properties and change the URL. Let's see what I mean.
Here's the complete list of properties that you can change:
The only property you can't set is window.location.origin . This property is read-only.
# Location Object
The window.location returns a Location object. Which gives you information about the current location of the page. But you can also access the Location object in several ways.
The reason we can do this is because these are global variables in our browser.

# window.location vs location
All 4 of these properties point at the same Location object. I personally prefer window.location and would actually avoid using location . Mainly because location reads more like a generic term and someone might accidentally name their variable that, which would override the global variable. Take for example:
I think that most developer is aware that window is a global variable. So you're less likely to cause confusion. To be honest, I had no idea location was a global variable until I wrote this post 😅. So my recommendation is to be more explicit and use window.location instead 👍
Here's my personal order of preference:
Of course, this is just my preference. You're the expert of your codebase, there is no best way, the best way is always the one that works best for you and your team 🤓
# window.location Methods
# window.location.tostring.
This method returns the USVString of the URL. It is a read-only version of Location.href
In other words, you can use it to get the href value from the
on this 😊. But I did find a performance test on the difference.
JSPerf: Location toString vs Location href
One thing I want to note about these speed tests is that it is browser specific. Different browser and versions will render different outcome. I'm using Chrome, so the href came out faster then the rest. So that's one I'll use. Also I think it reads more explicit then toString() . It is very obvious that href will provide the URL whereas toString seems like something it being converted to a string 😅
# assign vs replace
Both of these methods will help you redirect or navigate to another URL. The difference is assign will save your current page in history, so your user can use the "back" button to navigate to it. Whereas with replace method, it doesn't save it. Confused? No problem, I was too. Let's walk through an example.
Current Page
I just need to emphasize the "current page" in the definition. It is the page right before you call assign or replace .
# How to Do a Page Redirect
By now, you know we can change the properties of the window.location by assigning a value using = . Similarly, there are methods we can access to do some actions. So in regards to "how to redirect to another page", well there are 3 ways.
# replace vs assign vs href
All three does redirect, the difference has to do with browser history. href and assign are the same here. It will save your current page in history, whereas replace won't. So if you prefer creating an experience where the navigation can't press back to the originating page, then use replace 👍
So the question now is href vs assign . I guess this will come to personal preference. I like the assign better because it's a method so it feels like I'm performing some action. Also there's an added bonus of it being easier to test. I've been writing a lot of Jest tests, so by using a method, it makes it way easier to mock.
But for that that are rooting for href to do a page redirect. I found a performance test and running in my version of Chrome, it was faster. Again performance test ranges with browser and different versions, it may be faster now, but perhaps in future browsers, the places might be swapped.
JSPerf: href vs assign
# Scratch your own itch 👍
Okay, a bit of a tangent and give you a glimpse of how this cheatsheet came to be. I was googling how to redirect to another page and encountered the window.location object. Sometimes I feel a developer is a journalist or detective - there's a lot of digging and combing through multiple sources for you to gather all the information available. Honestly, I was overwhelmed with the materials out there, they all covered different pieces, but I just wanted a single source. I couldn't find much, so I thought, I'll cover this in a tidbit cheatsheet! Scratch your own itch I always say 👍
# Community Input
: This is awesome, I’ve used window.location.href in the past, but didn’t realise how simple it is to access sections of the URL!
If you want to see a live-action of what James is talking about, check out the table of content at the top of this article. Click on it and it will scroll down to the specific section of the page.
# Resources
- Share to Twitter Twitter
- Share to Facebook Facebook
- Share to LinkedIn LinkedIn
- Share to Reddit Reddit
- Share to Hacker News Hacker News
- Email Email
Related Tidbits
Console.table to display data, colorful console message, window.location cheatsheet, fresh tidbits.

HTML abbr Tag

How to Pad a String with padStart and padEnd in JavaScript

Avoid Empty Class in Vue with Null


Fix Text Overlap with CSS white-space

How to Check if Object is Empty in JavaScript
JS Reference
Html events, html objects, other references, window parent.
Change the background-color of the parent:
Definition and Usage
The parent property returns the parent window (of the current window).
The parent property is read-only.
The parent property is not the same as the top property.
window.parent returns the immediate parent of a window.
window.top returns the topmost window in the hierarchy of windows.
The top Property
Return Value
More examples.
The location of the parent window:
Browser Support
window.parent is supported in all browsers:

COLOR PICKER

Get your certification today!

Get certified by completing a course today!

Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
[email protected]
Your Suggestion:
Thank you for helping us.
Your message has been sent to W3Schools.
Top Tutorials
Top references, top examples, web certificates, get certified.
- No suggested jump to results
- Notifications
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window.Left and Window.Top are broken when usign PerMonitorV2 #4127
todor-dk commented Feb 3, 2021
- 👍 7 reactions
daveorourke commented Mar 4, 2021 • edited
- 👍 5 reactions
Sorry, something went wrong.
Perpete commented Nov 21, 2021 • edited
- 👍 2 reactions
markoweb2 commented Oct 4, 2022
MichaeIDietrich commented Oct 5, 2022
- 👍 1 reaction
Sandler commented Jan 9, 2023
dt200r commented Feb 22, 2023 • edited
lindexi commented Feb 23, 2023
Dt200r commented feb 23, 2023, daveorourke commented feb 24, 2023 • edited.
- 👀 2 reactions
dt200r commented Feb 24, 2023 • edited
No branches or pull requests
- KB Articles
- Version History
- Localization
- Support Center only
- All DevExpress web resources
We have closed this ticket because another page addresses its subject:
Answers approved by DevExpress Support
0 'other ' : '') + 'answers '">, recently viewed tickets.
- skip navigation Kendo UI for jQuery Product Bundles DevCraft All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with: NEW : Design Kits for Figma
problem with window.location after using hyperlink from template
Hello, I am very new at html and javascript so basic reponses would be better. Using this template location in a .html file <ul data-role="listview" data-source="app.data" data-template="LED-template"></ul> <script id="LED-template" type="text/x-kendo-template"> <a href="page/LEDlist/details.html?##id=#: LEDPartNumber #"> <div class="Manufacturer">#: LEDManufacturer #</div> <div class="Partnumber">#: LEDPartNumber #</div> </a> </script> gives me a list of all the data in app.data. Once any of the links are clicked this is executed var location = window.location.toString(); var partNumber = location.substring(location.lastIndexOf('?') + 4); it is able to get the partnumber which I can use to filter the total data to find the right data and create a page based on the information. The problem I am having is that after going back once and choosing a second partnumber the above code fails to return a valid reponse. I've attached the console that is outputing location and the partNumber
Thank you for any help!
7 Answers , 1 is accepted

Upon further investigation, it seems like window.location does not return the right value the second time the page is accessed. However, it works fine the first time.
The second (or third, etc) time the page is accessed, window.location returns the previous page, not the current one.
See attached picture.
Would you know what could cause this?
Hello again,here isthe base of my project. what I am sending you is able to run in the appbuilder simulator in the CLI with the error. to get the error, choose any LED and you will see the page with data, then press back and choose another the info on the next page will be wrong showing the first page again since the location is returning the wrong info.
[Attachment removed, in accordance with customer request.]

How do you detect navigation events in Blazor WebAssembly?
LocationChangedis an event handler that will fire when the navigation location has been changed. The following example uses a JavaScript interop function to alert the user when the navigation location changes.
Refer to this documentation for more details.
Related FAQs

Couldn't find the FAQs you're looking for?
Platform Blazor ASP.NET WinForms WPF Angular React
Answer (Optional)
Email (Optional)
Email address is only for further clarification on your FAQ request. It will not be used for any other purpose.
Please leave this field empty.

Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved
Fax: +1 919.573.0306, us: +1 919.481.1974, uk: +44 20 7084 6215, toll free: 1-888-9dotnet.
This web site uses cookies. By using the site you accept the cookie policy . This message is for compliance with the UK ICO law .
WPF Window Start-Up Locations
WPF windows can initially be displayed using three positioning options. The location of a window can be set manually, or the new window can be centred on the screen or in relation to its owner.
WindowStartupLocation
In the Windows Presentation Foundation Fundamentals tutorial , I described many properties of the Window class, which controls the display of windows and dialog boxes. The articles described how you can position a window manually using the Left and Top properties , which set the window's location relative to the top-left corner of the screen.
In many cases, you will want to centralise a window, either on the screen or relative to its owner. You could do this by obtaining the resolution of the screen, or the location and size of the parent window, calculating the correct location and setting the Left and Top properties. However, you can perform this type of positioning automatically by setting the WindowStartupLocation property to a constant from the WindowStartupLocation enumeration .
To demonstrate, create a new WPF application project in Visual Studio . Name the project, "WindowStartupLocationDemo". Once the solution is prepared, replace the XAML in the main window with the code below:
The above XAML creates a window with two buttons , each with its Click event registered. Switch to the code behind the window and ensure that the empty Click methods appear as follows:
Centring Windows
A common option for a newly loaded window is to centralise it on the screen. This can help to guide the user's attention to important items. Centralising on the screen is generally used when the window has no obvious owner or parent.
To open a new window and have it centred on the screen, set the WindowStartupLocation property to CenterScreen . You can do this using the XAML or in code before the window is displayed.
Let's configure the "Centre Screen" button to load a new instance of the main window in the middle of the screen. To do so, update the button's Click method, as follows:
Run the program and click the button to see the result.
Centring in an Owning Window
When you display a child window from an existing window, it can be useful to centralise the child relative to its parent. As the user should be looking at the parent, their attention should be quickly drawn to the child.
To centre a window in this way, the new window's Owner property should be set to the parent window's object. You also set the WindowStartupLocation property to CenterOwner .
To demonstrate, update the second click method, as shown below. Note that after the MainWindow object is created, the Owner is set and the start-up location option is selected. The child window is slightly smaller than its parent, as if it was the same size, it would obscure the original window.
Run the program again to try the new code.

IMAGES
VIDEO
COMMENTS
Remarks. A window's location changes when: A user moves a window by dragging it with the window's title bar. A window is moved after DragMove is called.
Any ideas? Many Thanks,. c# .net · wpf · events · window.
This is a simple application that shows how we can change window location in WPF. This robot follows your cursor forever.
There are two events associated when the dialog window's state changes. These events have the suffix “ing” or “ed” appended to them, reflecting the order in
The only property you can't set is window.location.origin . This property is read-only. # Location Object. The window.location returns a Location object
window.parent returns the immediate parent of a window. ... The location of the parent window:.
A window can be freely moved between the available monitors and WPF automatically changes scaling and other parameters.
Issue is , When we click on button 'Push' it is triggering the OK button click event of the popup. TestApp.zip.
The Router instance has a change event that provides access to the view parameters. The event can be attached via bind():
LocationChangedis an event handler that will fire when the navigation location has been changed. The following example uses a JavaScript interop
WPF windows can initially be displayed using three positioning options. The location of a window can be set manually, or the new window can