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


C# Coordinate.ToAbsolute方法代码示例

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


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

示例1: ToAbsolute

 public void ToAbsolute()
 {
     // 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
     Point a = c1.ToAbsolute(null);
     Assert.AreEqual(a.X, p.X);
     Assert.AreEqual(a.Y, p.Y);
     Assert.Catch<NullReferenceException>(() => c2.ToAbsolute(null));
     Assert.Catch<NullReferenceException>(() => c3.ToAbsolute(null));
     // Normal calls
     Point a1 = c1.ToAbsolute(w);
     Assert.AreEqual(a1.X, p.X);
     Assert.AreEqual(a1.Y, p.Y);
     Point r = c2.ToAbsolute(w);
     Assert.AreEqual(r.X, 700);
     Assert.AreEqual(r.Y, 700);
     Point s = c3.ToAbsolute(w);
     Assert.AreEqual(s.X, 696);
     Assert.AreEqual(s.Y, 620);
 }
开发者ID:antgraf,项目名称:BA,代码行数:26,代码来源:CoordinateTest.cs

示例2: Click

 private void Click(MouseActions action, Coordinate point, bool moveCursor)
 {
     ActivateIfNeeded();
     int x = 0;
     int y = 0;
     MouseFlag absflag = MouseFlag.Empty;
     if(moveCursor)
     {
         SetCursorPosition(point);
     }
     else
     {
         Point pt = point.ToAbsolute(this);
         x = pt.X;
         y = pt.Y;
         absflag = MouseFlag.Absolute;
     }
     switch(action)
     {
         case MouseActions.LeftClick:
         {
             InputSimulator.SimulateClickPress(MouseFlag.LeftDown | absflag, MouseFlag.LeftUp | absflag, x, y);
             break;
         }
         case MouseActions.LeftDown:
         {
             InputSimulator.SimulateClick(MouseFlag.LeftDown | absflag, x, y);
             break;
         }
         case MouseActions.LeftUp:
         {
             InputSimulator.SimulateClick(MouseFlag.LeftUp | absflag, x, y);
             break;
         }
         case MouseActions.MiddleClick:
         {
             InputSimulator.SimulateClickPress(MouseFlag.MiddleDown | absflag, MouseFlag.MiddleUp | absflag, x, y);
             break;
         }
         case MouseActions.MiddleDown:
         {
             InputSimulator.SimulateClick(MouseFlag.MiddleDown | absflag, x, y);
             break;
         }
         case MouseActions.MiddleUp:
         {
             InputSimulator.SimulateClick(MouseFlag.MiddleUp | absflag, x, y);
             break;
         }
         case MouseActions.RightClick:
         {
             InputSimulator.SimulateClickPress(MouseFlag.RightDown | absflag, MouseFlag.RightUp | absflag, x, y);
             break;
         }
         case MouseActions.RightDown:
         {
             InputSimulator.SimulateClick(MouseFlag.RightDown | absflag, x, y);
             break;
         }
         case MouseActions.RightUp:
         {
             InputSimulator.SimulateClick(MouseFlag.RightUp | absflag, x, y);
             break;
         }
         case MouseActions.X1Click:
         {
             InputSimulator.SimulateClickPress(MouseFlag.XDown | absflag, MouseFlag.XUp | absflag, 1, x, y);
             break;
         }
         case MouseActions.X1Down:
         {
             InputSimulator.SimulateClick(MouseFlag.XDown | absflag, 1, x, y);
             break;
         }
         case MouseActions.X1Up:
         {
             InputSimulator.SimulateClick(MouseFlag.XUp | absflag, 1, x, y);
             break;
         }
         case MouseActions.X2Click:
         {
             InputSimulator.SimulateClickPress(MouseFlag.XDown | absflag, MouseFlag.XUp | absflag, 2, x, y);
             break;
         }
         case MouseActions.X2Down:
         {
             InputSimulator.SimulateClick(MouseFlag.XDown | absflag, 2, x, y);
             break;
         }
         case MouseActions.X2Up:
         {
             InputSimulator.SimulateClick(MouseFlag.XUp | absflag, 2, x, y);
             break;
         }
         default:
         {
             throw new ArgumentException("Invalid action.", "action");
         }
     }
 }
开发者ID:antgraf,项目名称:BA,代码行数:100,代码来源:Window.cs

示例3: Radius

 protected double Radius(Coordinate center, Coordinate radiusPoint)
 {
     Point centerpt = center.ToAbsolute(this);
     Point radiuspt = radiusPoint.ToAbsolute(this);
     int diffx = centerpt.X - radiuspt.X;
     int diffy = centerpt.Y - radiuspt.Y;
     return Math.Sqrt(diffx * diffx + diffy * diffy);
 }
开发者ID:antgraf,项目名称:BA,代码行数:8,代码来源:Window.cs

示例4: SetCursorPosition

 public virtual void SetCursorPosition(Coordinate point)
 {
     Point abs = point.ToAbsolute(this);
     System.Drawing.Point pt = new System.Drawing.Point(abs.X, abs.Y);
     Cursor.Position = pt;
 }
开发者ID:antgraf,项目名称:BA,代码行数:6,代码来源:Window.cs

示例5: Screenshot

 public Bitmap Screenshot(Coordinate topLeft, Coordinate bottomRight)
 {
     ActivateIfNeeded();
     Point pt1 = topLeft.ToAbsolute(this);
     Point pt2 = bottomRight.ToAbsolute(this);
     Bitmap screenshot = new Bitmap(pt2.X - pt1.X, pt2.Y - pt1.Y, PixelFormat.Format32bppArgb);
     using(Graphics gdi = Graphics.FromImage(screenshot))
     {
         gdi.CopyFromScreen(pt1.X, pt1.Y, 0, 0, new Size(pt2.X - pt1.X, pt2.Y - pt1.Y), CopyPixelOperation.SourceCopy);
     }
     return screenshot;
 }
开发者ID:antgraf,项目名称:BA,代码行数:12,代码来源:Window.cs

示例6: Resize

 public virtual void Resize(Coordinate rightBottom)
 {
     Point pt = rightBottom.ToAbsolute(Desktop.Primary);
     WinApi.SetWindowPos(Handle.Handle, IntPtr.Zero, 0, 0, pt.X, pt.Y, WinApi.SwpNoMove | WinApi.SwpNoZOrder);
 }
开发者ID:antgraf,项目名称:BA,代码行数:5,代码来源:Window.cs

示例7: Move

 public virtual void Move(Coordinate position)
 {
     Point pt = position.ToAbsolute(Desktop.Primary);
     WinApi.SetWindowPos(Handle.Handle, IntPtr.Zero, pt.X, pt.Y, 0, 0, WinApi.SwpNoSize | WinApi.SwpNoZOrder);
 }
开发者ID:antgraf,项目名称:BA,代码行数:5,代码来源:Window.cs

示例8: GetPixelColor

 public Color GetPixelColor(Coordinate pixel)
 {
     ActivateIfNeeded();
     Point pt = pixel.ToAbsolute(this);
     IntPtr hdc = WinApi.GetDC(IntPtr.Zero);
     uint colorint = WinApi.GetPixel(hdc, pt.X, pt.Y);
     WinApi.ReleaseDC(IntPtr.Zero, hdc);
     Color color = Color.FromArgb((int)(colorint & 0x000000FF),
         (int)(colorint & 0x0000FF00) >> 8,
         (int)(colorint & 0x00FF0000) >> 16);
     return color;
 }
开发者ID:antgraf,项目名称:BA,代码行数:12,代码来源:Window.cs

示例9: FindColorInRectangle

 public Coordinate FindColorInRectangle(Color color, Coordinate topLeft, Coordinate bottomRight)
 {
     ActivateIfNeeded();
     using(Bitmap bmp = Screenshot(topLeft, bottomRight))
     {
         for(int y = 0; y < bmp.Height; y++)
             for(int x = 0; x < bmp.Width; x++)
             {
                 if(CompareColors(color, bmp.GetPixel(x, y)))
                 {
                     Point origin = topLeft.ToAbsolute(this);
                     return new Coordinate(CoordinateType.Absolute, new Point() { X = origin.X + x, Y = origin.Y + y });
                 }
             }
     }
     return null;
 }
开发者ID:antgraf,项目名称:BA,代码行数:17,代码来源:Window.cs

示例10: FindColorInCircle

        public Coordinate FindColorInCircle(Color color, Coordinate center, Coordinate radiusPoint)
        {
            ActivateIfNeeded();

            Point centerpt = center.ToAbsolute(this);
            double radius = Radius(center, radiusPoint);
            int left = (int)(centerpt.X - radius);
            left = left < 0 ? 0 : left;
            int top = (int)(centerpt.Y - radius);
            top = top < 0 ? 0 : top;
            int right = (int)(centerpt.X + radius);
            right = right >= Width ? Width - 1 : right;
            int bottom = (int)(centerpt.Y + radius);
            bottom = bottom >= Height ? Height - 1 : bottom;

            using(Bitmap bmp = Screenshot(
                new Coordinate(CoordinateType.Absolute, new Point() { X = left, Y = top }),
                new Coordinate(CoordinateType.Absolute, new Point() { X = right, Y = bottom })))
            {
                for(int y = 0; y < bmp.Height; y++)
                    for(int x = 0; x < bmp.Width; x++)
                    {
                        if(CompareColors(color, bmp.GetPixel(x, y)))
                        {
                            if(IsInRadius(new Point() { X = x + left, Y = y + top }, centerpt, radius))
                            {
                                return new Coordinate(CoordinateType.Absolute, new Point() { X = left + x, Y = top + y });
                            }
                        }
                    }
            }
            return null;
        }
开发者ID:antgraf,项目名称:BA,代码行数:33,代码来源:Window.cs

示例11: 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));
 }
开发者ID:antgraf,项目名称:BA,代码行数:19,代码来源:CoordinateTest.cs

示例12: 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));
 }
开发者ID:antgraf,项目名称:BA,代码行数:11,代码来源:CoordinateTest.cs


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