public static ClientToScreen ( |
||
element | ||
point | Point | |
return |
public static IntRect ClientToScreen(FrameworkElement element, Rect rect) { IntPoint topLeft = NativeMethods.ClientToScreen(element, new Point(rect.X, rect.Y)); IntPoint bottomRight = NativeMethods.ClientToScreen(element, new Point(rect.X + rect.Width, rect.Y + rect.Height)); return(new IntRect(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)); }
protected override void OnLostMouseCapture(MouseEventArgs e) { base.OnLostMouseCapture(e); if (this.bounds.Width < 3 || this.bounds.Height < 3) { CloseService(); return; } Cursor = Cursors.Arrow; IntRect startRect = NativeMethods.ClientToScreen(this, this.bounds); screenshot = new ScreenShot(startRect); startRect.Width -= 1; startRect.Height -= 1; IntRect screenBounds = ScreenCoordinates.Collapse(startRect, screenshot); Rect bounds = NativeMethods.ScreenToClient(this, screenBounds); if (!bounds.IsEmpty) { AnimateBounds(bounds); } isInDrawMode = false; Dimensions.CanClose = true; }
private void CaptureIt() { IntRect bounds = NativeMethods.ClientToScreen(this, Bounds); ScreenShot screenshot = new ScreenShot(bounds); Clipboard.SetImage(screenshot.Image); CloseService(); }
public static IntPoint ClientToScreen(FrameworkElement element, Point point) { PresentationSource source = PresentationSource.FromVisual(element); point = element.TransformToAncestor(source.RootVisual).Transform(point); Point offset = source.CompositionTarget.TransformToDevice.Transform(new Point(point.X, point.Y)); Win32Point winPt = new Win32Point((int)offset.X, (int)offset.Y); NativeMethods.ClientToScreen(((HwndSource)source).Handle, ref winPt); return(new IntPoint(winPt.x, winPt.y)); }
protected override void OnLostMouseCapture(MouseEventArgs e) { base.OnLostMouseCapture(e); if (this.bounds.Width == 0 || this.bounds.Height == 0) { this.CloseService(); return; } this.IsGrayed = false; this.Cursor = Cursors.Arrow; IntRect startRect = NativeMethods.ClientToScreen(this, this.bounds); startRect.Width -= 1; startRect.Height -= 1; IntRect screenBounds = ScreenCoordinates.Collapse(startRect, this.screenshot); if (!screenBounds.IsEmpty) { this.AnimateBounds(screenBounds); } this.BoundsRect.Visibility = Visibility.Visible; this.Dimensions.CanClose = true; //BitmapFrame frame = BitmapFrame.Create(this.screenshot.Image); //PngBitmapEncoder encoder = new PngBitmapEncoder(); //encoder.Frames.Add(frame); //using (FileStream fs = new FileStream(@"C:\tmp\ss.png", FileMode.Create, FileAccess.Write)) { // encoder.Save(fs); //}; }