|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Drawing; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading; |
| 7 | +using System.Windows; |
| 8 | +using System.Windows.Forms; |
| 9 | +using TestStack.White.Configuration; |
| 10 | + |
| 11 | +namespace TestStack.White.Drawing |
| 12 | +{ |
| 13 | + internal class ScreenRectangle |
| 14 | + { |
| 15 | + private Form form = new Form(); |
| 16 | + //TODO: Think about making color configurable |
| 17 | + private Color Color = Color.Red; |
| 18 | + |
| 19 | + internal ScreenRectangle(Rect rectangle) |
| 20 | + { |
| 21 | + form.FormBorderStyle = FormBorderStyle.None; |
| 22 | + form.ShowInTaskbar = false; |
| 23 | + form.TopMost = true; |
| 24 | + form.Left = 0; |
| 25 | + form.Top = 0; |
| 26 | + form.Width = 1; |
| 27 | + form.Height = 1; |
| 28 | + form.BackColor = this.Color; |
| 29 | + form.Opacity = 0.8; |
| 30 | + form.Visible = false; |
| 31 | + |
| 32 | + //Set popup style |
| 33 | + int num1 = TestStack.White.WindowsAPI.NativeWindow.GetWindowLong(form.Handle, -20); |
| 34 | + TestStack.White.WindowsAPI.NativeWindow.SetWindowLong(form.Handle, -20, num1 | 0x80); |
| 35 | + |
| 36 | + //Set position |
| 37 | + TestStack.White.WindowsAPI.NativeWindow.SetWindowPos(form.Handle, new IntPtr(-1), Convert.ToInt32(rectangle.X), Convert.ToInt32(rectangle.Y), |
| 38 | + Convert.ToInt32(rectangle.Width), Convert.ToInt32(rectangle.Height), 0x10); |
| 39 | + } |
| 40 | + |
| 41 | + internal virtual void Show() |
| 42 | + { |
| 43 | + TestStack.White.WindowsAPI.NativeWindow.ShowWindow(form.Handle, 8); |
| 44 | + } |
| 45 | + |
| 46 | + internal virtual void Hide() |
| 47 | + { |
| 48 | + form.Hide(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + internal class FrameRectangle |
| 53 | + { |
| 54 | + //Using 4 rectangles to display each border |
| 55 | + private ScreenRectangle leftBorder; |
| 56 | + private ScreenRectangle topBorder; |
| 57 | + private ScreenRectangle rightBorder; |
| 58 | + private ScreenRectangle bottomBorder; |
| 59 | + |
| 60 | + private ScreenRectangle[] rectangles; |
| 61 | + private int width = 3; |
| 62 | + |
| 63 | + internal FrameRectangle(Rect boundingRectangle) |
| 64 | + { |
| 65 | + leftBorder = new ScreenRectangle(new Rect(boundingRectangle.X - width, boundingRectangle.Y - width, width, boundingRectangle.Height + 2*width)); |
| 66 | + topBorder = new ScreenRectangle(new Rect(boundingRectangle.X, boundingRectangle.Y - width, boundingRectangle.Width, width)); |
| 67 | + rightBorder = new ScreenRectangle(new Rect(boundingRectangle.X + boundingRectangle.Width, boundingRectangle.Y - width, width, boundingRectangle.Height + 2*width)); |
| 68 | + bottomBorder = new ScreenRectangle(new Rect(boundingRectangle.X, boundingRectangle.Y + boundingRectangle.Height, boundingRectangle.Width, width)); |
| 69 | + rectangles = new ScreenRectangle[] { leftBorder, topBorder, rightBorder, bottomBorder }; |
| 70 | + } |
| 71 | + |
| 72 | + internal virtual void Highlight() |
| 73 | + { |
| 74 | + rectangles.ToList().ForEach(x => x.Show()); |
| 75 | + Thread.Sleep(CoreAppXmlConfiguration.Instance.HighlightTimeout); |
| 76 | + rectangles.ToList().ForEach(x => x.Hide()); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments