-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WpfHelpers.ToEtoScreen/ToNativeScreen helper methods
- Loading branch information
Showing
5 changed files
with
141 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Eto.Test.UnitTests; | ||
using NUnit.Framework; | ||
using swf = System.Windows.Forms; | ||
using sd = System.Drawing; | ||
|
||
namespace Eto.Test.Wpf.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ScreenToClientTests : TestBase | ||
{ | ||
|
||
class NonActivatingForm : swf.Form | ||
{ | ||
protected override bool ShowWithoutActivation => true; | ||
} | ||
|
||
[Test, ManualTest] | ||
public void ScreenLocationsShouldBeCorrect() | ||
{ | ||
var mre = new ManualResetEvent(false); | ||
Invoke(() => | ||
{ | ||
var wfwindows = new List<swf.Form>(); | ||
var windows = new List<Window>(); | ||
|
||
void CreateWindow(Rectangle rect) | ||
{ | ||
var window = new Form | ||
{ | ||
ShowActivated = false, | ||
ShowInTaskbar = false, | ||
Minimizable = false, | ||
Maximizable = false, | ||
Bounds = rect, | ||
Content = TableLayout.AutoSized("Click to dismiss", centered: true) | ||
}; | ||
window.MouseDown += (sender, e) => | ||
{ | ||
foreach (var w in windows) | ||
{ | ||
w.Close(); | ||
} | ||
foreach (var w in wfwindows) | ||
{ | ||
w.Close(); | ||
} | ||
mre.Set(); | ||
}; | ||
window.Show(); | ||
windows.Add(window); | ||
|
||
bool perMonitor = true; | ||
|
||
var sdrect = WpfHelpers.ToNativeScreen(rect, window.Screen, perMonitor: perMonitor).ToSD(); | ||
|
||
var wfwindow = new NonActivatingForm | ||
{ | ||
Bounds = sdrect, | ||
ShowInTaskbar = false, | ||
MinimizeBox = false, | ||
MaximizeBox = false, | ||
StartPosition = swf.FormStartPosition.Manual, | ||
BackColor = sd.Color.Blue | ||
}; | ||
wfwindow.Controls.Add(new swf.Label { Text = "Move me", Dock = swf.DockStyle.Fill, ForeColor = sd.Color.White }); | ||
wfwindow.LocationChanged += (sender, e) => | ||
{ | ||
var loc = wfwindow.RectangleToScreen(wfwindow.ClientRectangle); | ||
window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc, swf.Screen.FromControl(wfwindow), perMonitor: perMonitor); | ||
}; | ||
wfwindow.SizeChanged += (sender, e) => | ||
{ | ||
var loc = wfwindow.RectangleToScreen(wfwindow.ClientRectangle); | ||
window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc, swf.Screen.FromControl(wfwindow), perMonitor: perMonitor); | ||
}; | ||
wfwindow.Show(); | ||
wfwindows.Add(wfwindow); | ||
|
||
} | ||
|
||
foreach (var screen in Screen.Screens) | ||
{ | ||
var bounds = (Rectangle)screen.WorkingArea; | ||
var size = new Size(200, 200); | ||
CreateWindow(new Rectangle(bounds.TopLeft, size)); | ||
CreateWindow(new Rectangle(bounds.TopRight - new Size(size.Width, 0), size)); | ||
CreateWindow(new Rectangle(bounds.BottomLeft - new Size(0, size.Height), size)); | ||
CreateWindow(new Rectangle(bounds.BottomRight - size, size)); | ||
} | ||
}); | ||
mre.WaitOne(); | ||
} | ||
|
||
} | ||
} |