public static void AbsoluteToScreen(float x, float y, float z, ref int screenX, ref int screenY, Camera camera, System.Windows.Forms.Control form) { float xRatioOver = (x - camera.X) / camera.XEdge; xRatioOver += 1; xRatioOver /= 2.0f; float yRatioOver = (y - camera.Y) / camera.YEdge; yRatioOver -= 1; yRatioOver /= -2.0f; // get the top left // topLeftPoint = new System.Drawing.Point(form.ClientRectangle.Left, form.ClientRectangle.Top); float xPixelOver = xRatioOver * form.ClientRectangle.Width; float yPixelOver = yRatioOver * form.ClientRectangle.Height; System.Drawing.Point point = new System.Drawing.Point((int)xPixelOver, (int)yPixelOver); point = form.PointToScreen(point); screenX = point.X; screenY = point.Y; }
} // 1.0.003 private void ShowIt(bool showDialog, System.Windows.Forms.Control control, string editText) // 1.0.003 { // 1.0.003 System.Drawing.Point argPoint = new System.Drawing.Point(control.ClientRectangle.X, control.ClientRectangle.Y); // 1.0.003 argPoint = control.PointToScreen(argPoint); // 1.0.003 int argHeight = control.ClientRectangle.Height; // 1.0.003 int argWidth = control.ClientRectangle.Width; // 1.0.003 #region For certain types of Controls: Recompute [argPoint] [argHeight] [argWidth] if( (control.GetType() == typeof(System.Windows.Forms.TabPage)) // 1.0.003 || (control.GetType().IsSubclassOf(typeof(System.Windows.Forms.TabPage)) ) // 1.0.003 ) // 1.0.003 { // 1.0.003 System.Windows.Forms.TabPage tabPage = (System.Windows.Forms.TabPage)control; // 1.0.003 //System.Windows.Forms.Control tabParent = tabPage.GetContainerControl(); // 1.0.003 System.Windows.Forms.Control tabParent = tabPage.Parent; // 1.0.003 if( (tabParent != null) // 1.0.003 &&( (tabParent.GetType() == typeof(System.Windows.Forms.TabControl)) // 1.0.003 || (tabParent.GetType().IsSubclassOf(typeof(System.Windows.Forms.TabControl)) ) // 1.0.003 ) // 1.0.003 ) // 1.0.003 { // 1.0.003 System.Windows.Forms.TabControl tabCtl = (System.Windows.Forms.TabControl)tabParent; // 1.0.003 //int idx = tabPage.TabIndex; // Assumes [tabPage.TabIndex] is correct value // 1.0.003 int idx = tabCtl.TabPages.IndexOf(tabPage); // 1.0.003 System.Drawing.RectangleF tabRect = (System.Drawing.RectangleF)tabCtl.GetTabRect(idx); // 1.0.003 argPoint = tabCtl.PointToScreen(new System.Drawing.Point((int)tabRect.X, (int)tabRect.Y));// 1.0.003 argHeight = (int)tabRect.Height; // 1.0.003 argWidth = (int)tabRect.Width; // 1.0.003 } // 1.0.003 } // 1.0.003 #endregion string argEditText = editText.Trim(); // 1.0.003 if (argEditText.Length <= 0) // 1.0.003 { // 1.0.003 argEditText = control.Text.Trim(); // 1.0.003 } // 1.0.003 ShowIt(showDialog, argPoint, argHeight, argWidth, argEditText); // 1.0.003 } // 1.0.003
/// <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> /// 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); }
public static void ShowNotifyTip(System.Windows.Forms.TextBox textBox, string text, string title, Skybound.VisualTips.VisualTipNotifyIcon icon, int charIndex) { if ((textBox == null) || textBox.IsDisposed) throw new System.ArgumentNullException("textBox", "textBox may not be null or disposed."); if ((charIndex < 0) || (charIndex > textBox.TextLength)) throw new System.ArgumentNullException("charIndex", "charIndex may not be less than zero or greater than the length of the TextBox text."); if (charIndex == textBox.TextLength) charIndex = System.Math.Max(charIndex - 1, 0); System.IntPtr intPtr = Skybound.VisualTips.VisualTipProvider.SendMessage(textBox.Handle, 214, new System.IntPtr(System.Math.Max(charIndex, 0)), System.IntPtr.Zero); int i = intPtr.ToInt32(); System.Drawing.Point point = textBox.PointToScreen(new System.Drawing.Point(i)); System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(point, new System.Drawing.Size(1, textBox.Font.Height)); Skybound.VisualTips.VisualTipProvider.ShowNotifyTip(textBox, text, title, icon, Skybound.VisualTips.VisualTipDisplayOptions.HideOnKeyPress | Skybound.VisualTips.VisualTipDisplayOptions.HideOnLostFocus, rectangle); }
private static object GetComponentAtPoint(System.Windows.Forms.Control control, System.Drawing.Point point) { Skybound.VisualTips.IVisualTipExtender ivisualTipExtender = Skybound.VisualTips.VisualTipProvider.GetExtender(control.GetType()); object obj = ivisualTipExtender != null ? ivisualTipExtender.GetChildAtPoint(control, point.X, point.Y) : null; System.Windows.Forms.Control control1 = Skybound.VisualTips.VisualTipProvider.GetNestedChildAtPoint(control, control.PointToScreen(point)); if (control1 != control) return control1; return obj; }
/// <summary> /// 显示FloatForm。 /// 显示的坐标根据ctl的定位。OffsetX,OffsetY 是针对ctl的偏移。 /// </summary> /// <param name="ctl"></param> /// <param name="OffsetX"></param> /// <param name="OffsetY"></param> protected void ShowForm(System.Windows.Forms.Control ctl, int OffsetX, int OffsetY) { Point p = ctl.PointToScreen ( new Point ( OffsetX, OffsetY ) ) ; Location = p; StartTimer(); Show(); }
public void Show(System.Windows.Forms.Control control, Rectangle area, bool center) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); resizableTop = resizableLeft = false; Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (center) { if (location.X + (area.Width + Size.Width) / 2 > screen.Right) { resizableLeft = true; location.X = screen.Right - Size.Width; } else { resizableLeft = true; location.X = location.X - (Size.Width - area.Width) / 2; } } else { if (location.X + Size.Width > (screen.Left + screen.Width)) { resizableLeft = true; location.X = (screen.Left + screen.Width) - Size.Width; } } if (location.Y + Size.Height > (screen.Top + screen.Height)) { resizableTop = true; location.Y -= Size.Height + area.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
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; }
internal static ScreenInformation ScreenFromControl(System.Windows.Forms.Control control) { Rectangle r; if (control.Parent != null) { Point screenLocation = control.PointToScreen(control.Location); r = new Rectangle(screenLocation, control.Size); } else r = new Rectangle(control.Location, control.Size); if (m_Screens.Count == 0) RefreshScreens(); //foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens) foreach (ScreenInformation s in m_Screens) { //if(s.Bounds.Contains(r)) if (s.Bounds.Contains(r)) { return s; } } System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.FromControl(control); if (scr != null) return new ScreenInformation(scr.Bounds, scr.WorkingArea); return null; }
// Draw the grid or not private void DisplayOrHideGrid(Graphics gridGraphics, System.Windows.Forms.Control control) { Point pControl = control.PointToScreen(new Point(control.Location.X, control.Location.Y)); // Dispose the current grid if (gridGraphics != null) gridGraphics.Dispose(); gridGraphics = this.CreateGraphics(); // Horizontal lines gridGraphics.DrawLine(gridPen, 0, 0, 0, control.Height); gridGraphics.DrawLine(gridPen, control.Width - 1, 0, control.Width - 1, control.Height); for (int X = grid; X < control.Width; X += grid) { gridGraphics.DrawLine(gridPen, X, 0, X, control.Height); } // Vertical lines gridGraphics.DrawLine(gridPen, 0, 0, control.Width, 0); gridGraphics.DrawLine(gridPen, 0, control.Height - 1, control.Width, control.Height - 1); for (int Y = grid; Y < control.Height; Y += grid) { gridGraphics.DrawLine(gridPen, 0, Y, control.Width, Y); } }