public void TestThrowsOnGetAbsolutePositionWithoutScreen() { Control control = new Control(); Assert.Throws <InvalidOperationException>( delegate() { control.GetAbsoluteBounds(); } ); }
public void TestAbsoluteCoordinateTransformation() { // Create a test control that occupies 80 percent of the space in its // parent using unified coordinates Control myControl = new Control(); myControl.Bounds.Left = new UniScalar(0.1f, 0); myControl.Bounds.Top = new UniScalar(0.1f, 0); myControl.Bounds.Right = new UniScalar(0.9f, 0); myControl.Bounds.Bottom = new UniScalar(0.9f, 0); // Place the test control on a screen sized 1000 x 1000 pixels Screen myScreen = new Screen(1000.0f, 1000.0f); myScreen.Desktop.Children.Add(myControl); // Verify that the test control's absolute coordinates reflect its size // given in unified coordinates RectangleF absoluteBoundaries = myControl.GetAbsoluteBounds(); assertAlmostEqual(100.0f, absoluteBoundaries.Left); assertAlmostEqual(100.0f, absoluteBoundaries.Top); assertAlmostEqual(900.0f, absoluteBoundaries.Right); assertAlmostEqual(900.0f, absoluteBoundaries.Bottom); // Now change the size of the desktop to only one fourth of the screen myScreen.Desktop.Bounds.Location.X.Fraction = 0.5f; myScreen.Desktop.Bounds.Location.Y.Fraction = 0.5f; myScreen.Desktop.Bounds.Size.X.Fraction = 0.5f; myScreen.Desktop.Bounds.Size.Y.Fraction = 0.5f; // Verify that the desktop size change is reflected in the absolute // coordinates that control's GetAbsoluteBounds() method hands out absoluteBoundaries = myControl.GetAbsoluteBounds(); assertAlmostEqual(550.0f, absoluteBoundaries.Left); assertAlmostEqual(550.0f, absoluteBoundaries.Top); assertAlmostEqual(950.0f, absoluteBoundaries.Right); assertAlmostEqual(950.0f, absoluteBoundaries.Bottom); }
public void TestThrowsOnGetAbsolutePositionWithoutScreen() { Control control = new Control(); Assert.Throws<InvalidOperationException>( delegate() { control.GetAbsoluteBounds(); } ); }