https://github.com/tomaszrewak/messageboxpositionmanager
A small library that moves all newly created MessageBoxes to the center of their owner forms.
https://github.com/tomaszrewak/messageboxpositionmanager
center messagebox windowsforms wpf
Last synced: 4 months ago
JSON representation
A small library that moves all newly created MessageBoxes to the center of their owner forms.
- Host: GitHub
- URL: https://github.com/tomaszrewak/messageboxpositionmanager
- Owner: TomaszRewak
- License: mit
- Created: 2020-11-07T19:57:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-09T21:30:46.000Z (over 5 years ago)
- Last Synced: 2025-08-28T03:22:59.963Z (10 months ago)
- Topics: center, messagebox, windowsforms, wpf
- Language: C#
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MessageBoxPositionManager
A small library that moves all newly created MessageBoxes to the center of their owner forms.
Works well with both the `System.Windows.MessageBox` (WPF) and the `System.Windows.Forms.MessageBox` (WindowsForms).
To set it up simply install the package (`dotnet add package MessageBoxPositionManager`) and call the following static method from your UI thread (once, during the startup of your app):
```csharp
MessageBoxCenteringService.Initialize();
```
Later on, you can simply use the `MessageBox.Show` method to display new modals. No additional code is required to move the windows around.
If a MessageBox is attached to an owner, it will be rendered in a center of that window.
```csharp
MessageBox.Show(this, "Some content", "Title");
```
If a MessageBox is displayed without an owner, it will be rendered in a center of the currently active window or the center of the screen if no window is currently active.
```csharp
MessageBox.Show("Some content", "Title");
```
The package was create based on the ideas collected from [this StackOveflow thread](https://stackoverflow.com/questions/1732443/center-messagebox-in-parent-form).