本文整理汇总了C#中System.Coordinate.ToRelative方法的典型用法代码示例。如果您正苦于以下问题:C# Coordinate.ToRelative方法的具体用法?C# Coordinate.ToRelative怎么用?C# Coordinate.ToRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Coordinate
的用法示例。
在下文中一共展示了Coordinate.ToRelative方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToRelative
public void ToRelative()
{
// Init
Point p = CreateStdPoint();
StretchedPoint sp = CreateStdStretchedPoint();
Window w = CreateStdWindow();
Coordinate c1 = new Coordinate(CoordinateType.Absolute, p);
Coordinate c2 = new Coordinate(CoordinateType.Relative, p);
Coordinate c3 = new Coordinate(sp);
// Null argument
Assert.Catch<NullReferenceException>(() => c1.ToRelative(null));
Point r = c2.ToRelative(null);
Assert.AreEqual(r.X, p.X);
Assert.AreEqual(r.Y, p.Y);
Assert.Catch<NullReferenceException>(() => c3.ToRelative(null));
// Normal calls
Point a = c1.ToRelative(w);
Assert.AreEqual(a.X, -500);
Assert.AreEqual(a.Y, -300);
Point r1 = c2.ToRelative(w);
Assert.AreEqual(r1.X, p.X);
Assert.AreEqual(r1.Y, p.Y);
Point s = c3.ToRelative(w);
Assert.AreEqual(s.X, 96);
Assert.AreEqual(s.Y, 120);
}
示例2: PointInformation
private static string PointInformation()
{
StringBuilder text = new StringBuilder();
Window window = Window.GetWindowAtCursor();
Coordinate pt = new Coordinate(CoordinateType.Absolute, new WindowEntity.Point() { X = Cursor.Position.X, Y = Cursor.Position.Y });
Color color = Desktop.Primary.GetPixelColor(pt);
if(window != null)
{
WindowEntity.Point rel = pt.ToRelative(window);
StretchedPoint st = pt.ToStretched(window);
text.Append("<b>Window</b>: ");
text.AppendFormat("[{0}, {1}] ", window.Width, window.Height);
text.AppendFormat("\"{0}\"", window.Title);
text.AppendLine();
text.Append("<br><b>Color</b>: ");
text.AppendLine(color.ToString());
text.Append("<br><b>Coordinate</b>: Absolute: ");
text.AppendFormat("X = {0}, Y = {1}", pt.X, pt.Y);
text.Append("; Relative: ");
text.AppendFormat("X = {0}, Y = {1}", rel.X, rel.Y);
text.Append("; Stretched: ");
text.AppendFormat(CultureInfo.InvariantCulture, "X = {0}, Y = {1}", st.X, st.Y);
}
else
{
text.Append("<b>Color</b>: ");
text.AppendLine(color.ToString());
text.Append("<br><b>Coordinate</b>: Absolute: ");
text.AppendFormat("{0}, {1}", pt.X, pt.Y);
}
return text.ToString();
}
示例3: WrongCalls
public void WrongCalls()
{
Window w = CreateStdWindow();
Coordinate c0 = new Coordinate();
Assert.Catch<InitializationException>(() => c0.ToAbsolute(null));
Assert.Catch<InitializationException>(() => c0.ToAbsolute(w));
Assert.Catch<InitializationException>(() => c0.ToRelative(null));
Assert.Catch<InitializationException>(() => c0.ToRelative(w));
Assert.Catch<InitializationException>(() => c0.ToStretched(null));
Assert.Catch<InitializationException>(() => c0.ToStretched(w));
}
示例4: WrongPoint
public void WrongPoint()
{
StretchedPoint wrongP1 = new StretchedPoint {X = 100.0, Y = 0.0};
StretchedPoint wrongP2 = new StretchedPoint {X = 0.0, Y = 100.0};
StretchedPoint wrongP3 = new StretchedPoint {X = 100.0, Y = 200.0};
Coordinate c1 = new Coordinate(wrongP1);
Coordinate c2 = new Coordinate(wrongP2);
Coordinate c3 = new Coordinate(wrongP3);
Window w = CreateStdWindow();
Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToAbsolute(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToAbsolute(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToAbsolute(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToRelative(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToRelative(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToRelative(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToStretched(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToStretched(w));
Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToStretched(w));
}
示例5: FindImageCoordinate
private Coordinate FindImageCoordinate(Coordinate topLeft, Coordinate bottomRight, string imageName)
{
Bitmap screen = pEveWindow.Screenshot(topLeft, bottomRight);
SaveDebugImage(screen);
Bitmap fragment = new Bitmap(Relative2AbsolutePath(imageName));
pEveWindow.AllowedColorDeviation = pStandardColorDeviation;
Coordinate found = pEveWindow.FindImageWithColorDeviation(screen, fragment);
if(found == null)
{
return null;
}
WindowEntity.Point rel1 = topLeft.ToRelative(pEveWindow);
WindowEntity.Point rel2 = found.ToRelative(pEveWindow);
return new Coordinate(CoordinateType.Relative, new WindowEntity.Point() { X = rel1.X + rel2.X, Y = rel1.Y + rel2.Y });
}