/*******************************/ /// <summary> /// This method returns an Array of System.Int32 containing the size of the non client area of a control. /// The non client area includes elements such as scroll bars, borders, title bars, and menus. /// </summary> /// <param name="control">The control from which to retrieve the values.</param> /// <returns>An Array of System.Int32 containing the width of each non client area border in the following order /// top, left, right and bottom.</returns> public static System.Int32[] GetInsets(System.Windows.Forms.Control control) { System.Int32[] returnValue = new System.Int32[4]; returnValue[0] = (control.RectangleToScreen(control.ClientRectangle).Top - control.Bounds.Top); returnValue[1] = (control.RectangleToScreen(control.ClientRectangle).Left - control.Bounds.Left); returnValue[2] = (control.Bounds.Right - control.RectangleToScreen(control.ClientRectangle).Right); returnValue[3] = (control.Bounds.Bottom - control.RectangleToScreen(control.ClientRectangle).Bottom); return returnValue; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="ctr"></param> /// <param name="lastKeyEventArgs"></param> public override bool DoMouseMove(MouseEventArgs e, System.Windows.Forms.Control ctr, KeyEventArgs lastKeyEventArgs) { NPlot.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; // if mouse isn't in plot region, then don't draw horizontal line if (e.X > ps.PlotAreaBoundingBoxCache.Left && e.X < (ps.PlotAreaBoundingBoxCache.Right-1) && e.Y > ps.PlotAreaBoundingBoxCache.Top && e.Y < ps.PlotAreaBoundingBoxCache.Bottom) { if (ps.PhysicalXAxis1Cache != null) { // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); Point p = ctr.PointToScreen(new Point(e.X, e.Y)); if (barPos_ != -1) { ControlPaint.DrawReversibleLine( new Point(barPos_, clip.Top), new Point(barPos_, clip.Bottom), color_); } if (p.X < clip.Right && p.X > clip.Left) { ControlPaint.DrawReversibleLine( new Point(p.X, clip.Top), new Point(p.X, clip.Bottom), color_); barPos_ = p.X; } else { barPos_ = -1; } } } else { if (barPos_ != -1) { Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height) ); ControlPaint.DrawReversibleLine( new Point(barPos_, clip.Top), new Point(barPos_, clip.Bottom), color_); barPos_ = -1; } } return false; }
/// <summary> /// Handler for mouse leave event /// </summary> /// <param name="e">event args</param> /// <param name="ctr"></param> /// <returns></returns> public override bool DoMouseLeave(EventArgs e, System.Windows.Forms.Control ctr) { if (barPos_ != -1) { NPlot.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); ControlPaint.DrawReversibleLine( new Point(barPos_, clip.Top), new Point(barPos_, clip.Bottom), color_); barPos_ = -1; } return false; }
/// <summary> /// Draws a rectangle representing selection area. /// </summary> /// <param name="start">a corner of the rectangle.</param> /// <param name="end">a corner of the rectangle diagonally opposite the first.</param> /// <param name="ctr">The control to draw to - this may not be us, if we have /// been contained by a PlotSurface.</param> private void DrawRubberBand(Point start, Point end, System.Windows.Forms.Control ctr) { NPlot.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; Rectangle rect = new Rectangle(); // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); // convert to screen coords start = ctr.PointToScreen(start); end = ctr.PointToScreen(end); // now, "normalize" the rectangle if (start.X < end.X) { rect.X = start.X; rect.Width = end.X - start.X; } else { rect.X = end.X; rect.Width = start.X - end.X; } if (start.Y < end.Y) { rect.Y = start.Y; rect.Height = end.Y - start.Y; } else { rect.Y = end.Y; rect.Height = start.Y - end.Y; } rect = Rectangle.Intersect(rect, clip); ControlPaint.DrawReversibleFrame( new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), Color.White, FrameStyle.Dashed); }
private void DrawHorizontalSelection(Point start, Point end, System.Windows.Forms.Control ctr) { NPlot.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); start = ctr.PointToScreen(start); end = ctr.PointToScreen(end); ControlPaint.FillReversibleRectangle( new Rectangle((int)Math.Min(start.X, end.X), (int)clip.Y, (int)Math.Abs(end.X - start.X), (int)clip.Height), Color.White); }
private System.Drawing.Rectangle GetToolArea(System.Windows.Forms.Control control, object component) { System.Drawing.Rectangle rectangle = System.Drawing.Rectangle.Empty; if (!DisplayAtMousePosition) { if (component == null) { if (control is System.Windows.Forms.Form) { rectangle = System.Drawing.Rectangle.Empty; goto label_1; } return control.Parent.RectangleToScreen(control.Bounds); } Skybound.VisualTips.IVisualTipExtender ivisualTipExtender = Skybound.VisualTips.VisualTipProvider.GetExtender(control.GetType()); rectangle = ivisualTipExtender != null ? ivisualTipExtender.GetBounds(component) : System.Drawing.Rectangle.Empty; } label_1: if (rectangle != System.Drawing.Rectangle.Empty) return control.RectangleToScreen(rectangle); return new System.Drawing.Rectangle(System.Windows.Forms.Cursor.Position, new System.Drawing.Size(16, 16)); }
/// <summary> /// Captures the specified area of the control or whats underneath /// the control. If the argument flag client is true, only the client /// area of the control is captured, otherwise the entire control is /// captured. If the argument flag under is true, the capture area under /// the control is captured, otherwise the specified area on the control /// is captured. /// </summary> /// <param name="ctl">Control to capture</param> /// <param name="client">If true capture only client area else entire control.</param> /// <param name="under">If true capture specified area underneath the control else whats on the control.</param> /// <returns>bitmap image of the control or whats underneath the control</returns> public static Bitmap Control(System.Windows.Forms.Control ctl,bool client,bool under) { Bitmap bmp; // capture bitmap Rectangle ctlR; // capture area rectangle in control coordinates Rectangle scrR; // capture area rectangle in screen coordinates // get capture rectangle in control // coordinates and in screen coordinates if (client) // if capturing client area { ctlR = ctl.ClientRectangle; // get rectangle in control coordinates scrR = ctl.RectangleToScreen(ctlR); // get rectangle in screen coordinates } else // if capturing entire control { scrR = ctl.Bounds; // get rectangle in parent coordinates if (ctl.Parent != null) // if parent exists scrR = ctl.Parent.RectangleToScreen(scrR); // map to screen coordinates ctlR = ctl.RectangleToClient(scrR); // get rectangle in control coordinates } // capture an area under the control if (under) // if capture area is under control { bool prvV = ctl.Visible; // save control visibility if (prvV) // if control visible { ctl.Visible = false; // make control invisible Thread.Sleep(m_HDelay); // allow time for control to become invisible // prior to image capture } // Capture the bitmap using desktop window handle and screen coordinates // for the capture area. Note, the control window handle can NOT be used // for capturing an area under the control. IntPtr desktopHWND = USER32.GetDesktopWindow(); // get window handle for desktop bmp = Window(desktopHWND,scrR); // get bitmap for capture area under control if (ctl.Visible != prvV) // if control visibility was changed ctl.Visible = prvV; // restore previous visibility } // capture an area on the control else // if capture area not under control { // Capture the bitmap using control window handle and control coordinates // for capture area. bmp = Window(ctl.Handle,ctlR); // get bitmap using control window handle } return bmp; // return requested bitmap }
private void DrawHorizontalSelection(Point start, Point end, System.Windows.Forms.UserControl ctr) { // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps_.PlotAreaBoundingBoxCache.X, (int)ps_.PlotAreaBoundingBoxCache.Y, (int)ps_.PlotAreaBoundingBoxCache.Width, (int)ps_.PlotAreaBoundingBoxCache.Height)); start = ctr.PointToScreen(start); end = ctr.PointToScreen(end); }
private void DrawHorizontalSelection(Point start, Point end, System.Windows.Forms.Control ctr) { xuzhenzhen.com.chart.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); start = ctr.PointToScreen(start); end = ctr.PointToScreen(end); }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="ctr"></param> /// <param name="lastKeyEventArgs"></param> public override bool DoMouseMove(MouseEventArgs e, System.Windows.Forms.Control ctr, KeyEventArgs lastKeyEventArgs) { xuzhenzhen.com.chart.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; // if mouse isn't in plot region, then don't draw horizontal line if (e.X > ps.PlotAreaBoundingBoxCache.Left && e.X < ps.PlotAreaBoundingBoxCache.Right && e.Y > ps.PlotAreaBoundingBoxCache.Top && e.Y < (ps.PlotAreaBoundingBoxCache.Bottom-1)) { if (ps.PhysicalXAxis1Cache != null) { // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); Point p = ctr.PointToScreen(new Point(e.X, e.Y)); if (barPos_ != -1) { } if (p.Y < clip.Bottom && p.Y > clip.Top) { barPos_ = p.Y; } else { barPos_ = -1; } } } else { if (barPos_ != -1) { barPos_ = -1; } } return false; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="ctr"></param> /// <returns></returns> public override bool DoMouseLeave(EventArgs e, System.Windows.Forms.Control ctr) { if (barPos_ != -1) { xuzhenzhen.com.chart.PlotSurface2D ps = ((Windows.PlotSurface2D)ctr).Inner; Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps.PlotAreaBoundingBoxCache.X, (int)ps.PlotAreaBoundingBoxCache.Y, (int)ps.PlotAreaBoundingBoxCache.Width, (int)ps.PlotAreaBoundingBoxCache.Height)); barPos_ = -1; } return false; }
private static void UpdateClipForCursor(System.Windows.Forms.Form f) { if (MyMinerGame.Static.Window.NativeWindow.Handle == GetForegroundWindow() && MyGuiManager.GetScreenWithFocus() != null) System.Windows.Forms.Cursor.Clip = f.RectangleToScreen(f.ClientRectangle); }