当前位置: 首页>>代码示例>>C#>>正文


C# Rect.ToString方法代码示例

本文整理汇总了C#中System.Windows.Rect.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.ToString方法的具体用法?C# Rect.ToString怎么用?C# Rect.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Rect的用法示例。


在下文中一共展示了Rect.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveWindowBounds

 /// <summary>
 /// Save the restore bounds of the window.
 /// </summary>
 /// <param name="filename">The file to store the Rect data.</param>
 /// <param name="restoreBounds">The Rect object.</param>
 static public void SaveWindowBounds(string filename, Rect restoreBounds)
 {
     // Save restore bounds for the next time this window is opened
     IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly();
     using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, storage))
     using (StreamWriter writer = new StreamWriter(stream))
     {
         // Write restore bounds value to file
         writer.WriteLine(restoreBounds.ToString());
     }
 }
开发者ID:whztt07,项目名称:BIM-IFC,代码行数:16,代码来源:IFCUIUtility.cs

示例2: ToString_FormatException

		public void ToString_FormatException ()
		{
			// This test does not currently work because
			// String.Format does not throw all necessary exceptions
			IFormattable rFormattable = new Rect (1.0, 2.5, 3, 4);
			bool exceptionRaised = false;
			try {
				rFormattable.ToString ("{", null);
			} catch (FormatException) {
				exceptionRaised = true;
			}
			Assert.IsTrue (exceptionRaised, "Expected FormatException with IFormattable.ToString (\"{\", null)");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:13,代码来源:RectTest.cs

示例3: ToStringTest

		public void ToStringTest ()
		{
			Rect r = new Rect (1.0, 2.5, 3, 4);

			string expectedStringOutput = "1,2.5,3,4";
			Assert.AreEqual (expectedStringOutput, r.ToString ());
			Assert.AreEqual (expectedStringOutput, r.ToString (null));
			Assert.AreEqual ("Empty", Rect.Empty.ToString ());

			// IFormattable.ToString
			IFormattable rFormattable = r;
			Assert.AreEqual (expectedStringOutput,
				rFormattable.ToString (null, null),
				"IFormattable.ToString with null format");
			Assert.AreEqual (expectedStringOutput,
				rFormattable.ToString (string.Empty, null),
				"IFormattable.ToString with empty format");
			Assert.AreEqual ("1.00,2.50,3.00,4.00",
				rFormattable.ToString ("N2", null),
				"IFormattable.ToString with N2 format");
			Assert.AreEqual ("blah,blah,blah,blah",
				rFormattable.ToString ("blah", null),
				"IFormattable.ToString with blah format");
			Assert.AreEqual (":,:,:,:",
				rFormattable.ToString (":", null),
				"IFormattable.ToString with : format");
			Assert.AreEqual ("Empty",
				((IFormattable) Rect.Empty).ToString ("blah", null),
				"IFormattable.ToString on Rect.Empty with blah format");

			foreach (CultureInfo culture in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
				if (culture.IsNeutralCulture)
					continue;
				string separator = ",";
				if (culture.NumberFormat.NumberDecimalSeparator == separator)
					separator = ";";
				expectedStringOutput =
					1.ToString (culture) + separator +
					2.5.ToString (culture) + separator +
					3.ToString (culture) + separator +
					4.ToString (culture);
				Assert.AreEqual (expectedStringOutput,
					r.ToString (culture),
					"ToString with Culture: " + culture.Name);
				Assert.AreEqual ("Empty",
					Rect.Empty.ToString (culture),
					"ToString on Empty with Culture: " + culture.Name);

				// IFormattable.ToString
				Assert.AreEqual (expectedStringOutput,
					rFormattable.ToString (null, culture),
					"IFormattable.ToString with null format with Culture: " + culture.Name);
				Assert.AreEqual (expectedStringOutput,
					rFormattable.ToString (string.Empty, culture),
					"IFormattable.ToString with empty format with Culture: " + culture.Name);
				expectedStringOutput =
					1.ToString ("N2", culture) + separator +
					2.5.ToString ("N2", culture) + separator +
					3.ToString ("N2", culture) + separator +
					4.ToString ("N2", culture);
				Assert.AreEqual (expectedStringOutput,
					rFormattable.ToString ("N2", culture),
					"IFormattable.ToString with N2 format with Culture: " + culture.Name);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:65,代码来源:RectTest.cs

示例4: TS_VerifyWithinRects

        static void TS_VerifyWithinRects(Rect outerRect, Rect[] innerRects, GetBoundRectResult getBoundRectResult, CheckType checkType)
        {
            double areaOuter = 0;
            double areaInner = 0;

            // Sanity check... are any of our inners outside our outer?
            for (int i = 0; i < innerRects.Length; i++)
            {
                if ((innerRects[i].Top < outerRect.Top)
                 || (innerRects[i].Left < outerRect.Left)
                 || (innerRects[i].Right > outerRect.Right)
                 || (innerRects[i].Bottom > outerRect.Bottom))
                {
                    ThrowMe(checkType, "InnerRect " + innerRects[i].ToString(CultureInfo.InvariantCulture) +
                            " incorrectly outside autoElement.BoundRect " + outerRect.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    areaInner += (innerRects[i].Bottom - innerRects[i].Top) * (innerRects[i].Right - innerRects[i].Left);

                    Comment("Bounding Rectangle # " + i + " (" + innerRects[i].ToString(CultureInfo.InvariantCulture) +
                            ") within autoElement.BoundRect " + outerRect.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Now, lets split some hairs
            areaOuter = (outerRect.Bottom - outerRect.Top) * (outerRect.Right - outerRect.Left);
            Comment("Inner area = " + areaInner);
            Comment("Outer area = " + areaOuter);

            // Now, validate results
            switch (getBoundRectResult)
            {
                case GetBoundRectResult.SubsetOfAutoElementBoundRect:
                    if (areaInner < areaOuter)
                        Comment("Inner rectangle(s) is/are expected size, i.e. a small portion of the outer rectangle");
                    else if (innerRects.Length == 0)
                        ThrowMe(checkType, "Was not expecting an EMPTY array of bounding rectangles");
                    else
                        ThrowMe(checkType, "Unexpected state for test");
                    break;
                case GetBoundRectResult.EmptyArray:
                    if (innerRects.Length == 0)
                        Comment("Empty array of bounding rectangles, as expected");
                    else 
                        ThrowMe(checkType, "Was not expecting an a NON-EMPTY array of bounding rectangles");
                    break;
                default:
                    throw new ArgumentException("TS_VerifyWithinRects() has no support for " + ParseType(getBoundRectResult));
            }

            m_TestStep++;
        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:53,代码来源:TextTestsHelper.cs

示例5: GetAutomationElementBoundingRectangle

        //---------------------------------------------------------------------------
        // Acquire valid bounding rectangle for AutomationElement
        //---------------------------------------------------------------------------
        internal void GetAutomationElementBoundingRectangle(out Rect boundingRect)
        {
            // FxCop doesn't like calls that return object and box value types
            // hence the two step process for getting a property
            object temp = m_le.GetCurrentPropertyValue(
                                            AutomationElement.BoundingRectangleProperty);
            boundingRect = (Rect)temp;

            Comment("AutomationElement Bounding Rectangle = " + boundingRect.ToString(CultureInfo.InvariantCulture));
        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:13,代码来源:TextTestsHelper.cs

示例6: TS_CreatePoint

        internal void TS_CreatePoint(ref TextPatternRange range, Rect[] boundRects, out Point screenLocation, BoundingRectangleLocation boundRectLoc, CheckType checkType)
        {
            int rectIdx = 0;
            Rect autoElementRect = new Rect();
            Rect[] tempRects = new Rect[0];
            TextPatternRange documentRange = Pattern_DocumentRange(CheckType.Verification);

            screenLocation = new Point();

            // Sanity check
            Library.ValidateArgumentNonNull(range, "range argument cannot be null");

            if ((boundRects.Length == 0) && (boundRectLoc != BoundingRectangleLocation.OutsideAutomationElement))
            {
                throw new ArgumentException("TS_CreatePoint requires non-empty array of bounding rectangles");
            }

            // Finally, generate the point!
            switch (boundRectLoc)
            {
                case BoundingRectangleLocation.InsideTopLeft:
                    rectIdx = 0;
                    screenLocation.X = boundRects[rectIdx].Left + 1;
                    screenLocation.Y = boundRects[rectIdx].Top + 1;
                    break;
                case BoundingRectangleLocation.Middle:
                    screenLocation.X = (boundRects[rectIdx].Left + boundRects[rectIdx].Right) / 2;
                    screenLocation.Y = (boundRects[rectIdx].Top + boundRects[rectIdx].Bottom) / 2;
                    break;
                case BoundingRectangleLocation.InsideBottomRight:
                    rectIdx = boundRects.Length - 1;
                    screenLocation.X = boundRects[rectIdx].Right - 1;
                    screenLocation.Y = boundRects[rectIdx].Bottom - 1;
                    break;
                case BoundingRectangleLocation.OutsideBottomRight:
                    rectIdx = boundRects.Length - 1;
                    screenLocation.X = boundRects[rectIdx].Right + 1;
                    screenLocation.Y = boundRects[rectIdx].Bottom + 1;
                    break;
                case BoundingRectangleLocation.OutsideTopLeft:
                    rectIdx = 0;
                    screenLocation.X = boundRects[rectIdx].Left - 1;
                    screenLocation.Y = boundRects[rectIdx].Top - 1;
                    break;
                case BoundingRectangleLocation.OutsideAutomationElement:
                    // Get automation element bounding rectangle
                    GetAutomationElementBoundingRectangle(out autoElementRect);
                    screenLocation.X = autoElementRect.Left - 1;
                    screenLocation.Y = autoElementRect.Top - 1;
                    break;
                case BoundingRectangleLocation.FirstChar:
                    tempRects = null;
                    Range_GetBoundingRectangles(documentRange, ref tempRects, null, checkType);
                    if (tempRects.Length == 0)
                        ThrowMe(checkType, "TS_CreatePoint expects non-empy bounding rectangles array for document");
                    screenLocation.X = tempRects[0].Left + 1; // essentially top-left of first rect
                    screenLocation.Y = tempRects[0].Top + 1;
                    break;
                case BoundingRectangleLocation.FirstCharInRange:
                    rectIdx = 0;
                    screenLocation.X = boundRects[0].Left + 1; // essentially top-left of first rect
                    screenLocation.Y = boundRects[0].Top + 1;
                    break;
                case BoundingRectangleLocation.LastCharInRange:
                    rectIdx = boundRects.Length - 1;
                    screenLocation.X = boundRects[rectIdx].Right - 1;   // essentially bottom-right of last rect
                    screenLocation.Y = boundRects[rectIdx].Bottom - 1;
                    break;
                default:
                    throw new ArgumentException("TS_CreatePoint() has no support for " + ParseType(boundRectLoc));
            }

            Comment("Created Point (" + screenLocation.ToString(CultureInfo.InvariantCulture) + ") at " +
                    Parse(boundRectLoc) +
                    " relative to boundRect " +
                    (boundRectLoc != BoundingRectangleLocation.OutsideAutomationElement ?
                        boundRects[rectIdx].ToString(CultureInfo.InvariantCulture) :
                        autoElementRect.ToString(CultureInfo.InvariantCulture)));
            m_TestStep++;

        }
开发者ID:sergeyDyadenchuk,项目名称:Testing,代码行数:81,代码来源:TextTestsHelper.cs

示例7: ToStringIFormatProvider

		public void ToStringIFormatProvider ()
		{
			Rect r = new Rect (-2, -1, 1, 2);
			RectFormatter.CallCount = 0;
			Assert.AreEqual ("-2,-1,1,2", r.ToString (null), "null");
			Assert.AreEqual (0, RectFormatter.CallCount, "CallCount-a");
			Assert.AreEqual ("[-2]#[-1]#[1]#[2]", r.ToString (new RectFormatter ()), "RectFormatter");
			// 7 times: one per double (4) and 3 for ','
			Assert.AreEqual (7, RectFormatter.CallCount, "CallCount");
		}
开发者ID:kangaroo,项目名称:moon,代码行数:10,代码来源:RectTest.cs

示例8: TestToString

		public void TestToString ()
		{
			Rect rect = new Rect (10, 20, 30, 40);
			Assert.AreEqual ("10,20,30,40", rect.ToString ());
		}
开发者ID:kangaroo,项目名称:moon,代码行数:5,代码来源:RectTest.cs

示例9: ClickablePointPropertyTest

		public virtual void ClickablePointPropertyTest ()
		{
			IRawElementProviderSimple provider = GetProvider ();

			bool offscreen 
				= (bool) provider.GetPropertyValue (AutomationElementIdentifiers.IsOffscreenProperty.Id);
			object clickablePointObj 
				= provider.GetPropertyValue (AutomationElementIdentifiers.ClickablePointProperty.Id);

			Point clickablePoint = new Point (0, 0);

			// Clickable point should be either null or Rect.Empty
			if (offscreen) {
				if (clickablePointObj != null) {
					try {
						clickablePoint = (Point) clickablePointObj;
						Assert.IsTrue (clickablePoint.X >= 0,
						               string.Format ("X is negative, your provider should be OffScreen: {0}", clickablePoint.X));
						Assert.IsTrue (clickablePoint.Y >= 0,
						               string.Format ("Y is negative, your provider should be OffScreen: {0}", clickablePoint.Y));

					} catch (InvalidCastException) {
						Assert.Fail (string.Format ("You are not returning System.Windows.Point in ClickablePointProperty: {0}",
						                            clickablePoint,GetType ()));
					}
				}
			// Clickable point should intersect bounding rectangle...
			} else {
				if (clickablePointObj == null) // ...unless you are not clickable at all
					return;

				Assert.IsNotNull (clickablePoint, 
				                  "Your ClickablePointProperty should not be null.");

				try {
					clickablePoint = (Point) clickablePointObj;
					Assert.IsTrue (clickablePoint.X >= 0,
					               string.Format ("X is negative, your provider should be OffScreen: {0}", clickablePoint.X));
					Assert.IsTrue (clickablePoint.Y >= 0,
					               string.Format ("Y is negative, your provider should be OffScreen: {0}", clickablePoint.Y));

				} catch (InvalidCastException) {
					Assert.Fail (string.Format ("You are not returning System.Windows.Point in ClickablePointProperty: {0}",
					                            clickablePoint.GetType ()));
				}

				object boundingRectangle
					= provider.GetPropertyValue (AutomationElementIdentifiers.BoundingRectangleProperty.Id);
				Assert.IsNotNull (boundingRectangle, 
				                  "You need to return BoundingRectangle if you return ClickablePointProperty.");

				try {
					Rect boundingRectangleRect = (Rect) boundingRectangle;
					Assert.AreNotEqual (Rect.Empty, 
					                    boundingRectangleRect,
					                    "BoundingRectangle SHOULD NOT be Rect.Empty");

					Rect clickablePointRect = new Rect (clickablePoint.X, clickablePoint.Y, 1, 1);

					Assert.IsTrue (boundingRectangleRect.Contains (clickablePointRect),
					               string.Format ("ClickablePoint ({0}) SHOULD Intersect with BoundingRectangle: {1}",
					                              clickablePointRect.ToString (), 
					                              boundingRectangleRect.ToString ()));
					
				} catch (InvalidCastException) {
					Assert.Fail (string.Format ("You are not returning System.Windows.Rect in BoundingRectangle: {0}",
					                            boundingRectangle.GetType ()));
				}
			}
		}
开发者ID:mono,项目名称:uia2atk,代码行数:70,代码来源:BaseProviderTest.cs

示例10: SaveWindowSize

 private static void SaveWindowSize(object sender, EventArgs e)
 {
     WindowBaseViewModel model = (WindowBaseViewModel)sender;
     string key = model.GetType().AssemblyQualifiedName;
     Rect rect = new Rect(model.Surface.Top, model.Surface.Left, model.Surface.Width, model.Surface.Height);
     if (Properties.Settings.Default.WindowSizeState == null)
         Properties.Settings.Default.WindowSizeState = new System.Collections.Specialized.StringDictionary();
     if (Properties.Settings.Default.WindowSizeState.ContainsKey(key))
         Properties.Settings.Default.WindowSizeState[key] = rect.ToString();
     else
         Properties.Settings.Default.WindowSizeState.Add(key, rect.ToString());
     Properties.Settings.Default.Save();
 }
开发者ID:hjlfmy,项目名称:Rubezh,代码行数:13,代码来源:DialogService.cs


注:本文中的System.Windows.Rect.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。