PointToScreen() public method

public PointToScreen ( Point p ) : Point
p Point
return Point
		public static Size GetTipSize(Control control, Graphics graphics, TipSection tipData)
		{
			Size tipSize = Size.Empty;
			SizeF tipSizeF = SizeF.Empty;
			
			RectangleF workingArea = GetWorkingArea(control);
			
			PointF screenLocation = control.PointToScreen(Point.Empty);
			
			SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
			                                workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
			
			if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
				graphics.TextRenderingHint =
					TextRenderingHint.AntiAliasGridFit;
				
				tipData.SetMaximumSize(maxLayoutSize);
				tipSizeF = tipData.GetRequiredSize();
				tipData.SetAllocatedSize(tipSizeF);
				
				tipSizeF += new SizeF(HorizontalBorder * 2,
				                      VerticalBorder   * 2);
				tipSize = Size.Ceiling(tipSizeF);
			}
			
			if (control.ClientSize != tipSize) {
				control.ClientSize = tipSize;
			}
			
			return tipSize;
		}
Example #2
0
        // 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);
            }
        }
Example #3
0
        private void Show(System.Windows.Forms.Control control, Rectangle area)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }


            Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height));

            Rectangle screen = Screen.FromControl(control).WorkingArea;

            if (location.X + Size.Width > (screen.Left + screen.Width))
            {
                location.X = (screen.Left + screen.Width) - Size.Width;
            }

            if (location.Y + Size.Height > (screen.Top + screen.Height))
            {
                location.Y -= Size.Height + area.Height;
            }

            location = control.PointToClient(location);

            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }
Example #4
0
		public DragObject(ReportRootDesigner designer, Control dragControl, object hitTestObject, int initialX, int initialY)
		{
			m_designer = designer;
			m_dragControl = dragControl;
			m_hitObject = hitTestObject;
			m_initialX = initialX;
			m_initialY = initialY;
			m_mouseOffset = new Point(0, 0);
			m_screenOffset = new Point(0, 0);
			m_screenOffset = dragControl.PointToScreen(m_screenOffset);

			// The drag actually consists of all objects that are currently selected.
			//
			ISelectionService ss = designer.SelectionService;
			IDesignerHost host = designer.Host;

			m_dragShapes = new ArrayList();

			if (ss != null && host != null)
			{
				ICollection selectedObjects = ss.GetSelectedComponents();
				foreach(object o in selectedObjects)
				{
					IComponent comp = o as IComponent;
					if (comp != null)
					{
						ItemDesigner des = host.GetDesigner(comp) as ItemDesigner;
						if (des != null)
						{
							m_dragShapes.Add(des);
						}
					}
				}
			}
		}
Example #5
0
        public PopupWindow(Control parent, string caption, Point location, bool mayBeToLeft)
        {
            m_message = caption;

            InitializeComponent();

            SizeF sizef = messageLabel.CreateGraphics().MeasureString(m_message, messageLabel.Font);
            int labelWidth = (int)(sizef.Width * 1.05f);	// need just a little bit to make sure it stays single line
            int labelHeight = (int)(sizef.Height);

            Rectangle bounds = new Rectangle(location.X + SHIFT_HORIZ, location.Y - SHIFT_VERT, labelWidth, labelHeight);
            if(mayBeToLeft && parent != null)
            {
                try
                {
                    Rectangle parentBounds = new Rectangle(parent.PointToScreen(new Point(0, 0)), parent.Size);
                    //m_message = "" + parentBounds;
                    if(!parentBounds.Contains(bounds))
                    {
                        bounds = new Rectangle(location.X - labelWidth - SHIFT_HORIZ, location.Y - SHIFT_VERT, labelWidth, labelHeight);
                    }
                }
                catch {}
            }
            this.Bounds = bounds;

            messageLabel.Text = m_message;
            this.Focus();	// this normally won't work as Project.ShowPopup tries to return focus to parent. Hover mouse to regain focus
        }
Example #6
0
 /// <summary>
 /// Shows the form on the specifies parent in the specifies location.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="startLocation"></param>
 /// <param name="width"></param>
 public void Show(Control parent, Point startLocation, int width)
 {
     _parentControl = parent;
     Point location = parent.PointToScreen(startLocation);
     this.Location = location;            
     this.Width = width;
     this.Show();
 }
Example #7
0
        public static Bitmap TakeSnapshot(System.Windows.Forms.Control ctl)
        {
            Bitmap bmp = new Bitmap(ctl.Size.Width, ctl.Size.Height);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.CopyFromScreen(ctl.PointToScreen(ctl.ClientRectangle.Location), new Point(0, 0), ctl.ClientRectangle.Size);
            return(bmp);
        }
Example #8
0
		public static Size GetTipSize(Control control, Graphics graphics, TipSection tipData)
		{
			Size tipSize = Size.Empty;
			SizeF tipSizeF = SizeF.Empty;
			
			if (workingArea == RectangleF.Empty) {
				Form ownerForm = control.FindForm();
				if (ownerForm.Owner != null) {
					ownerForm = ownerForm.Owner;
				}
				
				workingArea = Screen.GetWorkingArea(ownerForm);
			}
			
			PointF screenLocation = control.PointToScreen(Point.Empty);
			SizeF maxLayoutSize = new SizeF(workingArea.Right /*- screenLocation.X*/ - HorizontalBorder * 2,
			                                workingArea.Bottom /*- screenLocation.Y*/ - VerticalBorder * 2);
			
			float global_max_x = workingArea.Right - HorizontalBorder * 2;
			
			if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
				/*graphics.TextRenderingHint =
				TextRenderingHint.AntiAliasGridFit;*/
				tipData.GlobalMaxX = global_max_x;
				tipData.SetMaximumSize(maxLayoutSize);
				//if (tipData.LeftOffset > 0) 
				//	control.Left = control.Left - tipData.LeftOffset;
				tipSizeF = tipData.GetRequiredSize();
				tipData.SetAllocatedSize(tipSizeF);
				
				tipSizeF += new SizeF(HorizontalBorder * 2,
				                      VerticalBorder   * 2);
				tipSize = Size.Ceiling(tipSizeF);
			}
			if (control is ICSharpCode.TextEditor.Gui.InsightWindow.PABCNETInsightWindow)
			{
				Rectangle rect = Rectangle.Ceiling(workingArea);
				Point pt = (control as ICSharpCode.TextEditor.Gui.InsightWindow.PABCNETInsightWindow).GetCusorCoord();
				if (pt.X + tipSize.Width > rect.Width)
				{
					control.Location = new Point(rect.Width-tipSize.Width,pt.Y);
				}
			}
			else
			{
				Rectangle rect = Rectangle.Ceiling(workingArea);
				Point pt = control.Location;
				if (pt.X + tipSize.Width > rect.Width)
				{
					control.Location = new Point(rect.Width-tipSize.Width,pt.Y);
				}
			}
			if (control.ClientSize != tipSize) {
				control.ClientSize = tipSize;
			}
			
			return tipSize;
		}
Example #9
0
        private void Control_MouseMove(object sender, MouseEventArgs e)
        {
            // convert the mouse coords from control codes to screen coords
            // and then to form coords
            System.Windows.Forms.Control ctrl = (System.Windows.Forms.Control)sender;
            Point pt = this.PointToClient(ctrl.PointToScreen(e.Location));

            this.ShowCoords(pt.X, pt.Y);
        }
        /// <summary>
        /// 生成控件图片,带边框
        /// </summary>
        /// <param name="control">要生成图片的控件</param>
        /// <returns>图片</returns>
        private static System.Drawing.Bitmap CreateControlImgBorder(System.Windows.Forms.Control control)
        {
            var bitmap         = new System.Drawing.Bitmap(control.ClientRectangle.Width, control.ClientRectangle.Height);
            var g              = System.Drawing.Graphics.FromImage(bitmap);
            var srcScreenPoint = control.PointToScreen(control.Location);
            var screenPoint    = new System.Drawing.Point(srcScreenPoint.X - control.Location.X, srcScreenPoint.Y - control.Location.Y);

            g.CopyFromScreen(screenPoint, new System.Drawing.Point(0, 0), new System.Drawing.Size(bitmap.Width, bitmap.Height));
            g.Dispose();
            return(bitmap);
        }
        public static void VirtualPaint(IVirtualTransparencyHost host, Control child, PaintEventArgs args)
        {
            Control hostControl = (Control)host;
            bool rtl = host is Form && ((Form)host).RightToLeft == RightToLeft.Yes && ((Form)host).RightToLeftLayout;

            Point childLocation = child.PointToScreen(new Point(0, 0));
            Point hostLocation = hostControl.PointToScreen(new Point(rtl ? hostControl.ClientSize.Width : 0, 0));
            Point relativeChildLocation = new Point(childLocation.X - hostLocation.X, childLocation.Y - hostLocation.Y);

            if (relativeChildLocation == Point.Empty)
            {
                // no translation transform required
                host.Paint(args);
                return;
            }

            Rectangle relativeClipRectangle = args.ClipRectangle;
            relativeClipRectangle.Offset(relativeChildLocation);
            args.Graphics.SetClip(relativeClipRectangle, CombineMode.Replace);

            // Global transformations applied in GDI+ land don't apply to
            // GDI calls. So we need to drop down to GDI, apply a transformation
            // there, then wrap with GDI+.

            IntPtr hdc = args.Graphics.GetHdc();
            try
            {
                Gdi32.GraphicsMode oldGraphicsMode = Gdi32.SetGraphicsMode(hdc, Gdi32.GraphicsMode.Advanced);

                Gdi32.XFORM xformOrig;
                Gdi32.GetWorldTransform(hdc, out xformOrig);
                try
                {
                    Gdi32.XFORM xform = xformOrig;
                    xform.eDx -= relativeChildLocation.X;
                    xform.eDy -= relativeChildLocation.Y;
                    Gdi32.SetWorldTransform(hdc, ref xform);

                    using (Graphics g = Graphics.FromHdc(hdc))
                    {
                        host.Paint(new PaintEventArgs(g, relativeClipRectangle));
                    }
                }
                finally
                {
                    Gdi32.SetWorldTransform(hdc, ref xformOrig);
                    Gdi32.SetGraphicsMode(hdc, oldGraphicsMode);
                }
            }
            finally
            {
                args.Graphics.ReleaseHdc(hdc);
            }
        }
Example #12
0
		public static Size DrawTip(Control control, Graphics graphics, TipSection tipData)
		{
			Size tipSize = Size.Empty;
			SizeF tipSizeF = SizeF.Empty;
			
			PointF screenLocation = control.PointToScreen(Point.Empty);
			
			if (workingArea == RectangleF.Empty) {
				Form ownerForm = control.FindForm();
				if (ownerForm.Owner != null) {
					ownerForm = ownerForm.Owner;
				}
				
				workingArea = Screen.GetWorkingArea(ownerForm);
			}
	
			SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
			                                workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
			
			if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
				//graphics.TextRenderingHint =
				//TextRenderingHint.AntiAliasGridFit;
				
				tipData.SetMaximumSize(maxLayoutSize);
				tipSizeF = tipData.GetRequiredSize();
				tipData.SetAllocatedSize(tipSizeF);
				
				tipSizeF += new SizeF(HorizontalBorder * 2,
				                      VerticalBorder   * 2);
				tipSize = Size.Ceiling(tipSizeF);
			}
			
			if (control.ClientSize != tipSize) {
				control.ClientSize = tipSize;
			}
			
			if (tipSize != Size.Empty) {
				Rectangle borderRectangle = new Rectangle
				(Point.Empty, tipSize - new Size(1, 1));
				
				RectangleF displayRectangle = new RectangleF
				(HorizontalBorder, VerticalBorder,
				 tipSizeF.Width - HorizontalBorder * 2,
				 tipSizeF.Height - VerticalBorder * 2);
				
				// DrawRectangle draws from Left to Left + Width. A bug? :-/
				graphics.DrawRectangle(SystemPens.WindowFrame,
				                       borderRectangle);
				tipData.Draw(new PointF(HorizontalBorder, VerticalBorder));
			}
			return tipSize;
		}
Example #13
0
 private static void AdjustLoacation(Control ctl)
 {
     if (formLoading != null)
     {
         formLoading.Size = ctl.Size;
         formLoading.Location = ctl.PointToScreen(new Point(0, 0));
         formLoading.pbLoading.Location = new Point((formLoading.Width - formLoading.pbLoading.Width) / 2
             , (formLoading.Height - formLoading.pbLoading.Height) / 2 - 10);
         formLoading.labelMsg.Location = new Point(
             (formLoading.Width - formLoading.labelMsg.Width) / 2,
             (formLoading.pbLoading.Location.X + formLoading.pbLoading.Height + 10));
     }
 }
Example #14
0
            /// <summary>
            /// Vrací souřadnice klientského prostoru uvnitř daného controlu = relativně k jeho Location
            /// </summary>
            /// <param name="control"></param>
            /// <returns></returns>
            internal static Rectangle GetClientBounds(WinForm.Control control)
            {
                Rectangle clientRectangle = control.ClientRectangle;

                if (control is WinForm.Form)
                {
                    Point absFormOrigin   = control.Location;
                    Point absClientOrigin = control.PointToScreen(Point.Empty);
                    Point relClientOrigin = new Point(absClientOrigin.X - absFormOrigin.X + clientRectangle.X, absClientOrigin.Y - absFormOrigin.Y + clientRectangle.Y);
                    clientRectangle = new Rectangle(relClientOrigin, clientRectangle.Size);
                }
                return(clientRectangle);
            }
Example #15
0
 private void PrintObject1_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         select.ShowMenu(con.PointToScreen(new Point(e.X, e.Y)));
     }
     if (e.Button == MouseButtons.Left)
     {
         if (this.sizebk != con.Size || this.locationbk != con.Location)
         {
             select.Record();
         }
     }
 }
        internal ThumbnailViewForm(Control baseControl, DiagramClientView diagramClientView)
        {
            if (baseControl == null)
            {
                throw new ArgumentNullException("baseControl");
            }
            if (diagramClientView == null)
            {
                throw new ArgumentNullException("diagramClientView");
            }

            // Initialize the form.
            TopMost = true;
            ShowInTaskbar = false;
            FormBorderStyle = FormBorderStyle.None;
            StartPosition = FormStartPosition.Manual;

            // Position form so that its center lines up with the center of thumbnail control
            // at designer's bottom-right corner.
            var location = baseControl.PointToScreen(new Point(baseControl.Width / 2, baseControl.Height / 2));
            location.Offset(-ViewSize / 2, -ViewSize / 2);
            Bounds = new Rectangle(location.X, location.Y, ViewSize, ViewSize);

            // Make sure thumbnail form fits the screen and doesn't go below or off the right
            // edge of the screen.
            var screenBounds = Screen.FromControl(diagramClientView).WorkingArea;
            if (Right > screenBounds.Right)
            {
                Left = screenBounds.Right - Width;
            }
            if (Bottom > screenBounds.Bottom)
            {
                Top = screenBounds.Bottom - Height;
            }

            // Initialize a panel to host pan/zoom control.
            var panel1 = new Panel();
            panel1.Dock = DockStyle.Fill;
            panel1.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(panel1);

            // Initialize and dock pan/zoom control on the panel.
            _panZoomPanel = new PanZoomPanel();
            _panZoomPanel.Dock = DockStyle.Fill;
            panel1.Controls.Add(_panZoomPanel);
            _panZoomPanel.InvalidateImage(diagramClientView);

            Cursor.Hide();
        }
 private void Show(Control control, Point pos, int flags)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (!control.IsHandleCreated || !control.Visible)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("ContextMenuInvalidParent"), "control");
     }
     this.sourceControl = control;
     this.OnPopup(EventArgs.Empty);
     pos = control.PointToScreen(pos);
     System.Windows.Forms.SafeNativeMethods.TrackPopupMenuEx(new HandleRef(this, base.Handle), flags, pos.X, pos.Y, new HandleRef(control, control.Handle), null);
 }
 public void ShowForScope(Control control, Point pos)
 {
     List<Rectangle> rects = textBox.GetSurroundingRects(scope);
     Point screenPoint = control.PointToScreen(pos);
     Point clientPoint = control.PointToClient(screenPoint);
     Rectangle hitTest = new Rectangle(clientPoint, new Size(4,4));
     if(rects.Count>0)
     {
     //                ShowUnderScopeRect(rects[0], control.PointToScreen(pos), control);
         foreach (Rectangle rect in rects)
         {
             if(rect.IntersectsWith(hitTest))
             {
                 ShowUnderScopeRect(rect, control.PointToScreen(pos), control);
                 return;
             }
         }
         base.Show(control, pos);
     }
     else
     {
         base.Show(control, pos);
     }
 }
 private static void MouseLeaveExtend(this Control ctl, Action function, Control baseControl)
 {
     ctl.MouseLeave += (object sender, EventArgs arg) =>
     {
         Point p = Control.MousePosition;
         Rectangle r = new Rectangle(baseControl.PointToScreen(Point.Empty), baseControl.Size);
         if (!r.Contains(p))
         {
             function();
         }
     };
     foreach (Control c in ctl.Controls)
     {
         c.MouseLeaveExtend(function, baseControl);
     }
 }
Example #20
0
        public static Size DrawFixedWidthTip(Control control, Graphics graphics, TipSection tipData)
        {
            Size tipSize = Size.Empty;
            SizeF tipSizeF = SizeF.Empty;

            PointF screenLocation = control.PointToScreen(new Point(control.Width, 0));

            RectangleF workingArea = GetWorkingArea(control);

            SizeF maxLayoutSize = new SizeF(screenLocation.X - HorizontalBorder * 2,
                                            workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);

            if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
                graphics.TextRenderingHint =
                    TextRenderingHint.AntiAliasGridFit;

                tipData.SetMaximumSize(maxLayoutSize);
                tipSizeF = tipData.GetRequiredSize();
                tipData.SetAllocatedSize(tipSizeF);

                tipSizeF += new SizeF(HorizontalBorder * 2,
                                      VerticalBorder   * 2);
                tipSize = Size.Ceiling(tipSizeF);
            }

            if (control.Height != tipSize.Height) {
                control.Height = tipSize.Height;
            }

            if (tipSize != Size.Empty) {
                Rectangle borderRectangle = new Rectangle
                    (Point.Empty, control.Size - new Size(1, 1));

                RectangleF displayRectangle = new RectangleF
                    (HorizontalBorder, VerticalBorder,
                     tipSizeF.Width - HorizontalBorder * 2,
                     tipSizeF.Height - VerticalBorder * 2);

                // DrawRectangle draws from Left to Left + Width. A bug? :-/
                graphics.DrawRectangle(SystemPens.WindowFrame,
                                       borderRectangle);
                tipData.Draw(new PointF(HorizontalBorder, VerticalBorder));
            }
            return tipSize;
        }
Example #21
0
        public override string setValue(string val, string steering)
        {
            int clickCnt = 0;

            while (!StringHelpers.DoStringsMatch(getValue("", ""), val))
            {
                if (clickCnt++ >= 3)
                {
                    return("Der Eingabewert >" + val + "< konnte nicht in der Checkbox gefunden werden!");
                }
                Point clickPoint = ctrl.PointToScreen(new Point(ctrl.Width / 2, ctrl.Height / 2));
                TricentisLibs.MouseSteering.Click(clickPoint);
                Application.DoEvents();
                Thread.Sleep(10);
                Application.DoEvents();
            }
            return(ReturnOK);
        }
        public void Show(Control control, Point position)
        {
            if (control == null)
                Location = position;
            else
                Location = control.PointToScreen(Point.Empty) + position;
            int height = 0;
            int width = 160;
            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].JustVisual) continue;
                if (Items[i] is ToolStripMenuItem && !String.IsNullOrEmpty((Items[i] as ToolStripMenuItem).ShortcutKeys))
                    width = 220;
                height += 24;
            }
            Size = new Drawing.Size(width, height);

            if (Location.X + width > Screen.PrimaryScreen.WorkingArea.Width)
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - width, Location.Y);

            Visible = true;

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i] is ToolStripDropDownItem)
                {
                    var ddi = Items[i] as ToolStripDropDownItem;
                    ddi.ArrowImage = ApplicationBehaviour.Resources.Images.DropDownRightArrow;
                    ddi.ArrowColor = Color.Black;
                }
                Items[i].ForeColor = Color.FromArgb(64, 64, 64);
                Items[i].HoverColor = Color.FromArgb(160, 210, 222, 245);
                Items[i].TextAlign.LineAlignment = StringAlignment.Center;
                switch (Orientation)
                {
                    case Forms.Orientation.Horizontal:

                        break;
                    case Forms.Orientation.Vertical:
                        Items[i].Size = new Size(Size.Width, 24);
                        break;
                }
            }
        }
Example #23
0
        public static Image CaptureControl(Control ctr)
        {
            Screen scr = Screen.PrimaryScreen;
            Rectangle rc = scr.Bounds;
            int iWidth = rc.Width;
            int iHeight = rc.Height;
            //����һ������Ļһ�����Bitmap

            Image bmp = new Bitmap(ctr.Width, ctr.Height);
            //��һ���̳���Image��Ķ����д���Graphics����

            Graphics g = Graphics.FromImage(bmp);
            //ץ����������myimage��

            g.CopyFromScreen(ctr.PointToScreen(new Point(0, 0)), new Point(0, 0), new Size(ctr.Width, ctr.Height));

            //bmp.Save("final.jpg");
            g.Dispose();
            return bmp;
        }
Example #24
0
		/// <summary>
		/// Position this form in the centre of the specified control.
		/// </summary>
		internal void CentreInControl(Control control)
		{
			// max size of this form is the size of the specified control
			var maxSize = control.Size;

			// computer centre of host control in screen coordinates
			var centre = control.PointToScreen(new Point(0, 0));
			centre.Offset(control.Width / 2, control.Height / 2);

			// compute size of form
			var w = Math.Min(_idealSize.Width, maxSize.Width);
			var h = Math.Min(_idealSize.Height, maxSize.Height);

			// compute upper left corner location
			var x = centre.X - (w/2);
			var y = centre.Y - (h/2);
			
			// update position
			this.Bounds = new Rectangle(x, y, w, h);
		}
Example #25
0
        /// <summary> 显示颜色 
        /// </summary>
        /// <param name="ctl"></param>
        /// <param name="msg"></param>
        /// <param name="color"></param>
        public static void ShowMsg(Control ctl, string msg,Color color)
        {
            if (formMsg != null)
            {
                formMsg.Close();
                formMsg = null;
            }
            if (formBG == null || formBG.IsDisposed)
            {
                formBG = new FormBG();
            }                       
            //formBG.BringToFront();

            formMsg = new FormMessgeBox(msg,color);            
            formBG.Show();
            //formBG.BringToFront();
            formBG.Size = ctl.Size;
            formBG.Location = ctl.PointToScreen(new Point(0, 0));
            formMsg.Show();
            formMsg.Location = new Point(formBG.Location.X + (formBG.Width - formMsg.Width) / 2,
                formBG.Location.Y + (formBG.Height - formMsg.Height) / 2);            
        }
Example #26
0
        public void Show(Control control, Rectangle area)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            SetOwnerItem(control);
            resizableTop = resizableRight = false;
            Point     location = control.PointToScreen(new Point(area.Left, area.Top + area.Height));
            Rectangle screen   = Screen.FromControl(control).WorkingArea;

            if (location.X + Size.Width > (screen.Left + screen.Width))
            {
                resizableRight = 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);
        }
Example #27
0
 public void Show(Control control, int x, int y)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (!control.IsHandleCreated)
     {
         throw new ArgumentException();
     }
     ContextMenu contextMenu = control.ContextMenu;
     this.OnPopup(EventArgs.Empty);
     try
     {
         control.ContextMenu = this;
         Point point = control.PointToScreen(new Point(x, y));
         Interop.TrackPopupMenuEx(base.Handle, 0x40, point.X, point.Y, control.Handle, IntPtr.Zero);
     }
     finally
     {
         control.ContextMenu = contextMenu;
         this.OnClose(EventArgs.Empty);
     }
 }
Example #28
0
        private static bool GetColor(Control ctrl, Color initialColor, out Color resultColor, bool showNone = true)
        {
            var result = false;
            resultColor = Color.Black;
            const int offset = 6;

            using (var dialog = new ColorPicker(initialColor, showNone)) {
                dialog.Location = dialog.GetBestLocation(ctrl.PointToScreen(new Point(0, 0)), offset);
                dialog.ShowDialog();

                switch (dialog.DialogResult) {
                    case DialogResult.OK:
                        resultColor = dialog.GetColor();
                        result = true;
                        break;
                    case DialogResult.No:
                        resultColor = Color.Transparent;
                        result = true;
                        break;
                }
            }

            return result;
        }
Example #29
0
 public static object CallControlPointToScreen(Control c, object[] obj)
 {
     return(c.PointToScreen((System.Drawing.Point)obj[0]));
 }
    	// this should only be executed once per Form
    	public static API_WebScarab syncGuiPositionWithControl(this API_WebScarab webScarab, Control control)
    	{
		    Action moveToControl = 
				()=>{
						webScarab.alwaysOnTop(true); 
						var xPos =  control.PointToScreen(System.Drawing.Point.Empty).X;
						var yPos =  control.PointToScreen(System.Drawing.Point.Empty).Y;
						var width = control.width();
						var height = control.height();
						webScarab.moveWindow(xPos, yPos, width, height);  
					};	
						
			control.parentForm().Move += 
				(sender,e)=> moveToControl();
			 
			control.Resize +=  
				(sender,e)=> moveToControl();
			moveToControl();							
			return webScarab;
		}
Example #31
0
        public void ProcessMouse(MouseEvents mE, float mX, float mY, MouseButtons mButton, int clicks, int delta)
        {
            if (scaleX != 1f || scaleY != 1f)
            {
                mX /= scaleX;
                mY /= scaleY;
            }

            mouseEvent      = mE;
            mouseButton     = mButton;
            mouseWheelDelta = delta;

            mousePositionChanged = mousePositionX != mX || mousePositionY != mY;
            if (mousePositionChanged)
            {
                updateHoveredControl = true;
            }

            mousePositionX = mX;
            mousePositionY = mY;

            switch (mouseEvent)
            {
            case MouseEvents.None:
                if (!mousePositionChanged)
                {
                    return;
                }
                break;

            case MouseEvents.Down:
                mouseButtonLastPressed = mButton;
                break;

            case MouseEvents.Up:
                if (mouseButtonLastPressed == mButton)
                {
                    mouseButtonLastPressed = MouseButtons.None;
                }
                break;
            }


            // Dispose context first.
            for (int i = Contexts.Count - 1; i >= 0; i--) // We want to dispose child context first.
            {
                var contextControl = Contexts[i];
                if (!contextControl.uwfContext)
                {
                    continue;
                }

                if (Contains(contextControl, hoveredControl))
                {
                    continue;
                }
                if (mouseEvent != MouseEvents.Down)
                {
                    continue;
                }

                contextControl.Dispose();
            }

            var processedControl = mouseDownControl;

            if (processedControl == null || IsDragging)
            {
                processedControl = hoveredControl;
            }

            if (processedControl != null)
            {
                RaiseMouseEvents(new PointF(mX, mY), processedControl);
            }

            if (mouseEvent == MouseEvents.Up)
            {
                // Try raise MouseLeave event if mouse is outside of clicked control.
                if (mouseDownControl != null)
                {
                    var rect = new Rectangle(mouseDownControl.PointToScreen(Point.Empty), mouseDownControl.Size);
                    if (!rect.Contains((int)mousePositionX, (int)mousePositionY))
                    {
                        mouseDownControl.RaiseOnMouseLeave(EventArgs.Empty);
                    }
                }

                mouseDownControl = null;

                if (IsDragging)
                {
                    StopDragDrop();
                }
            }

            if (mouseEvent == MouseEvents.Down)
            {
                var downArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseDown(processedControl, downArgs);
            }

            if (mouseEvent == MouseEvents.Up)
            {
                var upArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseUp(processedControl, upArgs);
            }
        }
Example #32
0
		public void TestPublicMethods ()
		{
			// Public Methods that force Handle creation:
			// - CreateControl ()
			// - CreateGraphics ()
			// - GetChildAtPoint ()
			// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
			// - PointToClient ()
			// - PointToScreen ()
			// - RectangleToClient ()
			// - RectangleToScreen ()
			Control c = new Control ();
			
			c.BringToFront ();
			Assert.IsFalse (c.IsHandleCreated, "A1");
			c.Contains (new Control ());
			Assert.IsFalse (c.IsHandleCreated, "A2");
			c.CreateControl ();
			Assert.IsTrue (c.IsHandleCreated, "A3");
			c = new Control ();
			Graphics g = c.CreateGraphics ();
			g.Dispose ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c = new Control ();
			c.Dispose ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c = new Control ();
			//DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None);
			//Assert.IsFalse (c.IsHandleCreated, "A6");
			//Assert.AreEqual (DragDropEffects.None, d, "A6b");
			//Bitmap b = new Bitmap (100, 100);
			//c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100));
			//Assert.IsFalse (c.IsHandleCreated, "A7");
			//b.Dispose ();
			c.FindForm ();
			Assert.IsFalse (c.IsHandleCreated, "A8");
			c.Focus ();
			Assert.IsFalse (c.IsHandleCreated, "A9");

			c.GetChildAtPoint (new Point (10, 10));
			Assert.IsTrue (c.IsHandleCreated, "A10");
			c.GetContainerControl ();
			c = new Control ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.GetNextControl (new Control (), true);
			Assert.IsFalse (c.IsHandleCreated, "A12");
#if NET_2_0
			c.GetPreferredSize (Size.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
#endif
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "A14");
			c.Invalidate ();
			Assert.IsFalse (c.IsHandleCreated, "A15");
			//c.Invoke (new InvokeDelegate (InvokeMethod));
			//Assert.IsFalse (c.IsHandleCreated, "A16");
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A17");
			c.PointToClient (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A18");
			c = new Control ();
			c.PointToScreen (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A19");
			c = new Control ();
			//c.PreProcessControlMessage   ???
			//c.PreProcessMessage          ???
			c.RectangleToClient (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A20");
			c = new Control ();
			c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A21");
			c = new Control ();
			c.Refresh ();
			Assert.IsFalse (c.IsHandleCreated, "A22");
			c.ResetBackColor ();
			Assert.IsFalse (c.IsHandleCreated, "A23");
			c.ResetBindings ();
			Assert.IsFalse (c.IsHandleCreated, "A24");
			c.ResetCursor ();
			Assert.IsFalse (c.IsHandleCreated, "A25");
			c.ResetFont ();
			Assert.IsFalse (c.IsHandleCreated, "A26");
			c.ResetForeColor ();
			Assert.IsFalse (c.IsHandleCreated, "A27");
			c.ResetImeMode ();
			Assert.IsFalse (c.IsHandleCreated, "A28");
			c.ResetRightToLeft ();
			Assert.IsFalse (c.IsHandleCreated, "A29");
			c.ResetText ();
			Assert.IsFalse (c.IsHandleCreated, "A30");
			c.SuspendLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A31");
			c.ResumeLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A32");
#if NET_2_0
			c.Scale (new SizeF (1.5f, 1.5f));
			Assert.IsFalse (c.IsHandleCreated, "A33");
#endif
			c.Select ();
			Assert.IsFalse (c.IsHandleCreated, "A34");
			c.SelectNextControl (new Control (), true, true, true, true);
			Assert.IsFalse (c.IsHandleCreated, "A35");
			c.SetBounds (0, 0, 100, 100);
			Assert.IsFalse (c.IsHandleCreated, "A36");
			c.Update ();
			Assert.IsFalse (c.IsHandleCreated, "A37");
		}
        /// <summary>
        /// 在父容器中显示显示控件
        /// </summary>
        /// <param name="control">父容器</param>
        /// <param name="rect">显示区域</param>
        /// <param name="center">是否居中</param>
        public void Show(Control control, Rectangle rect, bool center)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            SetOwnerItem(control);

            if (_canResize && !_changeRegion)
            {
                Padding = new Padding(3);
            }
            else if (!_changeRegion)
            {
                Padding = new Padding(1);
            }
            else
            {
                Padding = Padding.Empty;
            }

            int width = Padding.Horizontal;
            int height = Padding.Vertical;

            base.Size = new Size(
                   _popupControl.Width + width,
                   _popupControl.Height + height);

            _resizableTop = false;
            _resizableLeft = false;
            Point location = control.PointToScreen(
                new Point(rect.Left, rect.Bottom));
            Rectangle screen = Screen.FromControl(control).WorkingArea;
            if (center)
            {
                if (location.X + (rect.Width + Size.Width) / 2 > screen.Right)
                {
                    location.X = screen.Right - Size.Width;
                    _resizableLeft = true;
                }
                else
                {
                    location.X = location.X - (Size.Width - rect.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 + rect.Height;
            }

            location = control.PointToClient(location);
            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }
Example #34
0
        internal static void RunLoop(bool Modal, ApplicationContext context)
        {
            Queue              toplevels;
            MSG                msg;
            Object             queue_id;
            MWFThread          thread;
            ApplicationContext previous_thread_context;

            thread = MWFThread.Current;

            /*
             * There is a NotWorking test for this, but since we are using this method both for Form.ShowDialog as for ApplicationContexts we'll
             * fail on nested ShowDialogs, so disable the check for the moment.
             */
            //if (thread.MessageLoop) {
            //        throw new InvalidOperationException ("Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.");
            //}

            msg = new MSG();

            if (context == null)
            {
                context = new ApplicationContext();
            }

            previous_thread_context = thread.Context;
            thread.Context          = context;

            if (context.MainForm != null)
            {
                context.MainForm.is_modal = Modal;
                context.MainForm.context  = context;
                context.MainForm.closing  = false;
                context.MainForm.Visible  = true;                       // Cannot use Show() or scaling gets confused by menus
                // XXX the above line can be used to close the form. another problem with our handling of Show/Activate.
                if (context.MainForm != null)
                {
                    context.MainForm.Activate();
                }
            }

                        #if DebugRunLoop
            Console.WriteLine("Entering RunLoop(Modal={0}, Form={1})", Modal, context.MainForm != null ? context.MainForm.ToString() : "NULL");
                        #endif

            if (Modal)
            {
                toplevels = new Queue();
                DisableFormsForModalLoop(toplevels, context);

                // FIXME - need activate?
                /* make sure the MainForm is enabled */
                if (context.MainForm != null)
                {
                    XplatUI.EnableWindow(context.MainForm.Handle, true);
                    XplatUI.SetModal(context.MainForm.Handle, true);
                }
            }
            else
            {
                toplevels = null;
            }

            queue_id           = XplatUI.StartLoop(Thread.CurrentThread);
            thread.MessageLoop = true;

            bool quit = false;

            while (!quit && XplatUI.GetMessage(queue_id, ref msg, IntPtr.Zero, 0, 0))
            {
                Message m = Message.Create(msg.hwnd, (int)msg.message, msg.wParam, msg.lParam);

                if (Application.FilterMessage(ref m))
                {
                    continue;
                }

                switch ((Msg)msg.message)
                {
                case Msg.WM_KEYDOWN:
                case Msg.WM_SYSKEYDOWN:
                case Msg.WM_CHAR:
                case Msg.WM_SYSCHAR:
                case Msg.WM_KEYUP:
                case Msg.WM_SYSKEYUP:
                    Control c = Control.FromHandle(msg.hwnd);

                    // If we have a control with keyboard capture (usually a *Strip)
                    // give it the message, and then drop the message
                    if (keyboard_capture != null)
                    {
                        // WM_SYSKEYUP does not make it into ProcessCmdKey, so do it here
                        if ((Msg)m.Msg == Msg.WM_SYSKEYDOWN)
                        {
                            if (m.WParam.ToInt32() == (int)Keys.Menu)
                            {
                                keyboard_capture.GetTopLevelToolStrip().Dismiss(ToolStripDropDownCloseReason.Keyboard);
                                continue;
                            }
                        }

                        m.HWnd = keyboard_capture.Handle;

                        switch (keyboard_capture.PreProcessControlMessageInternal(ref m))
                        {
                        case PreProcessControlState.MessageProcessed:
                            continue;

                        case PreProcessControlState.MessageNeeded:
                        case PreProcessControlState.MessageNotNeeded:
                            if (((m.Msg == (int)Msg.WM_KEYDOWN || m.Msg == (int)Msg.WM_CHAR) && !keyboard_capture.ProcessControlMnemonic((char)m.WParam)))
                            {
                                if (c == null || !ControlOnToolStrip(c))
                                {
                                    continue;
                                }
                                else
                                {
                                    m.HWnd = msg.hwnd;
                                }
                            }
                            else
                            {
                                continue;
                            }

                            break;
                        }
                    }

                    if (((c != null) && c.PreProcessControlMessageInternal(ref m) != PreProcessControlState.MessageProcessed) ||
                        (c == null))
                    {
                        goto default;
                    }
                    break;

                case Msg.WM_LBUTTONDOWN:
                case Msg.WM_MBUTTONDOWN:
                case Msg.WM_RBUTTONDOWN:
                    if (keyboard_capture != null)
                    {
                        Control c2 = Control.FromHandle(msg.hwnd);
                        var     contextMenuStrip = keyboard_capture.GetTopLevelToolStrip() as ContextMenuStrip;

                        // The target is not a winforms control (an embedded control, perhaps), so
                        // release everything
                        if (c2 == null)
                        {
                            ToolStripManager.FireAppClicked();
                            goto default;
                        }

                        // Skip clicks on owner windows, eg. expanded ComboBox
                        if (Control.IsChild(keyboard_capture.Handle, msg.hwnd))
                        {
                            goto default;
                        }

                        // Close any active toolstrips drop-downs if we click outside of them,
                        // but also don't close them all if we click outside of the top-most
                        // one, but into its owner.
                        Point c2_point = c2.PointToScreen(new Point(
                                                              (int)(short)(m.LParam.ToInt32() & 0xffff),
                                                              (int)(short)(m.LParam.ToInt32() >> 16)));
                        while (keyboard_capture != null && !keyboard_capture.ClientRectangle.Contains(keyboard_capture.PointToClient(c2_point)))
                        {
                            keyboard_capture.Dismiss();
                        }

                        var iter_OwnerItem = (c2 as ToolStripDropDown)?.OwnerItem;
                        while (iter_OwnerItem != null && iter_OwnerItem.Owner != contextMenuStrip)
                        {
                            iter_OwnerItem = iter_OwnerItem.OwnerItem;
                        }
                        var contextMenuStripIsOwnerOf_c2 = (iter_OwnerItem != null);

                        if (c2 != contextMenuStrip && !contextMenuStripIsOwnerOf_c2)
                        {
                            contextMenuStrip.Dismiss();
                        }
                    }
                    goto default;

                case Msg.WM_QUIT:
                    quit = true;                     // make sure we exit
                    break;

                default:
                    XplatUI.TranslateMessage(ref msg);
                    XplatUI.DispatchMessage(ref msg);
                    break;
                }

                // If our Form doesn't have a handle anymore, it means it was destroyed and we need to *wait* for WM_QUIT.
                if ((context.MainForm != null) && (!context.MainForm.IsHandleCreated))
                {
                    continue;
                }

                // Handle exit, Form might have received WM_CLOSE and set 'closing' in response.
                if ((context.MainForm != null) && (context.MainForm.closing || (Modal && !context.MainForm.Visible)))
                {
                    if (!Modal)
                    {
                        XplatUI.PostQuitMessage(0);
                    }
                    else
                    {
                        break;
                    }
                }
            }
                        #if DebugRunLoop
            Console.WriteLine("   RunLoop loop left");
                        #endif

            thread.MessageLoop = false;
            XplatUI.EndLoop(Thread.CurrentThread);

            if (Modal)
            {
                Form old = context.MainForm;

                context.MainForm = null;

                EnableFormsForModalLoop(toplevels, context);

                if (old != null && old.IsHandleCreated)
                {
                    XplatUI.SetModal(old.Handle, false);
                }
                                #if DebugRunLoop
                Console.WriteLine("   Done with the SetModal");
                                #endif
                old.RaiseCloseEvents(true, false);
                old.is_modal = false;
            }

                        #if DebugRunLoop
            Console.WriteLine("Leaving RunLoop(Modal={0}, Form={1})", Modal, context.MainForm != null ? context.MainForm.ToString() : "NULL");
                        #endif

            if (context.MainForm != null)
            {
                context.MainForm.context = null;
                context.MainForm         = null;
            }

            thread.Context = previous_thread_context;

            if (!Modal)
            {
                thread.Exit();
            }
        }
Example #35
0
        public void Show(Control control, Point position)
        {
            Location = control == null ? position : control.PointToScreen(Point.Empty).Add(position);

            SetVisibleCore();
        }
Example #36
0
 // use this function for all other popups - at least it catches exceptions
 // parent's bounds are used to make sure popup fits into the parent; otherwise supply null and popup will be to the right of the location
 public static void ShowPopup(Control parent, string caption, Point location)
 {
     if(location.IsEmpty && parent != null)
     {
         location = parent.PointToScreen(popupOffset);
     }
     Project._ShowPopup(parent, caption, location, false);
 }
Example #37
0
			/// <summary>
			/// Necessary method to support the designer
			/// </summary>
			private void InitializeComponent(Control Ctrl)
			{
				this.showValue = new System.Windows.Forms.Label();
				this.SuspendLayout();
				//
				// showValue
				//
				this.showValue.Dock = System.Windows.Forms.DockStyle.Fill;
				this.showValue.Location = new System.Drawing.Point(0, 0);
				this.showValue.Name = "showValue";
				this.showValue.Size = new System.Drawing.Size(140, 22);
				this.showValue.TabIndex = 0;
				this.showValue.Text = "0 %";
				this.showValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
				//
				// ProgressForm
				//
				this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
				this.ClientSize = new System.Drawing.Size(140, 22);
				this.ControlBox = false;
				this.Controls.Add(this.showValue);
				this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

				//
				//  check manual position
				Point pt = Ctrl.PointToScreen(new Point(0,0));
				this.Location = new System.Drawing.Point(
					pt.X + (Ctrl.Width  - this.Width )/2,
					pt.Y + (Ctrl.Height - this.Height)/3 );
				this.MaximizeBox = false;
				this.MinimizeBox = false;
				this.Name = "ProgressForm";
				this.ShowInTaskbar = false;
				this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
				this.TopMost = true;
				this.ResumeLayout(false);
			}
Example #38
0
        /// <summary>
        /// The show.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="target">
        /// The target.
        /// </param>
        /// <param name="arrowLocation">
        /// The arrow location.
        /// </param>
        /// <exception cref="ArgumentException">
        /// </exception>
        public void Show(string text, Control target, Point arrowLocation)
        {
            if (target == null)
            {
                throw new ArgumentException("Target control cannot be null");
            }

            var activeScreen = Screen.FromControl(target).WorkingArea;

            var contentSize = this.GetSize(text);
            var abLoc = target.PointToScreen(arrowLocation);
            abLoc.X -= contentSize.Width;
            abLoc.Y -= contentSize.Height / 2;

            int diffToScreenBottom = activeScreen.Bottom - (abLoc.Y + contentSize.Height);
            if (diffToScreenBottom < 0)
            {
                abLoc.Y += diffToScreenBottom;
            }

            var ttLoc = target.PointToClient(abLoc);
            this.Show(text, target, ttLoc);
        }
Example #39
0
        public void Show(Control control, Rectangle area)
        {
            if (control == null)
            {
                throw new ArgumentNullException("Parent control could not be null");
            }
            SetOwnerItem(control);

            Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height));
            Rectangle screen = Screen.FromControl(control).WorkingArea;
            if (location.X + Size.Width > (screen.Left + screen.Width))
            {
                location.X = (screen.Left + screen.Width) - Size.Width;
            }
            if (location.Y + Size.Height > (screen.Top + screen.Height))
            {
                location.Y -= Size.Height + area.Height;
            }
            location = control.PointToClient(location);
            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }
Example #40
0
        // Returns true if the message should be dropped.
        internal static IntPtr SendMessage(ref MSG msg, out bool drop, out bool quit)
        {
            drop = false;
            quit = false;
            Message m = Message.Create(msg.hwnd, (int)msg.message, msg.wParam, msg.lParam);

            if (Application.FilterMessage(ref m))
            {
                drop = true;
                return(IntPtr.Zero);
            }

            switch (msg.message)
            {
            case Msg.WM_KEYDOWN:
            case Msg.WM_SYSKEYDOWN:
            case Msg.WM_CHAR:
            case Msg.WM_SYSCHAR:
            case Msg.WM_KEYUP:
            case Msg.WM_SYSKEYUP:
                Control c = Control.FromHandle(msg.hwnd);
                if (c != null && !c.Enabled)
                {
                    break;
                }

                // If we have a control with keyboard capture (usually a *Strip)
                // give it the message, and then drop the message
                if (keyboard_capture != null && c != keyboard_capture && !Control.IsChild(keyboard_capture.Handle, c?.Handle ?? IntPtr.Zero))
                {
                    // WM_SYSKEYUP does not make it into ProcessCmdKey, so do it here
                    if (msg.message == Msg.WM_SYSKEYDOWN)
                    {
                        if (m.WParam.ToInt32() == (int)Keys.Menu)
                        {
                            keyboard_capture.GetTopLevelToolStrip().Dismiss(ToolStripDropDownCloseReason.Keyboard);
                            drop = true;
                            return(IntPtr.Zero);
                        }
                    }

                    m.HWnd = keyboard_capture.Handle;
                }
                goto default;

            case Msg.WM_LBUTTONDOWN:
            case Msg.WM_MBUTTONDOWN:
            case Msg.WM_RBUTTONDOWN:
            case Msg.WM_XBUTTONDOWN:
                Control c2 = Control.FromHandle(msg.hwnd);
                if (keyboard_capture != null)
                {
                    // The target is not a winforms control (an embedded control, perhaps), so
                    // release everything
                    if (c2 == null)
                    {
                        ToolStripManager.FireAppClicked();
                        goto default;
                    }

                    // Skip clicks on owner windows, eg. expanded ComboBox
                    if (Control.IsChild(keyboard_capture.Handle, msg.hwnd))
                    {
                        goto default;
                    }

                    // Native menus have their own closing mechanism.
                    if (ToolStripManager.DismissingHandledNatively)
                    {
                        goto default;
                    }

                    // Close any active toolstrips drop-downs if we click outside of them,
                    // but also don't close them all if we click outside of the top-most
                    // one, but into its owner.
                    Point c2_point = c2.PointToScreen(new Point((short)(m.LParam.ToInt32() & 0xffff), (short)(m.LParam.ToInt32() >> 16)));
                    while (keyboard_capture != null && !keyboard_capture.ClientRectangle.Contains(keyboard_capture.PointToClient(c2_point)))
                    {
                        keyboard_capture.Dismiss();
                    }
                }
                if (c2 != null && !c2.Enabled)
                {
                    break;
                }
                goto default;

            case Msg.WM_LBUTTONDBLCLK:
            case Msg.WM_MBUTTONDBLCLK:
            case Msg.WM_RBUTTONDBLCLK:
            case Msg.WM_XBUTTONDBLCLK:
                Control dbl = Control.FromHandle(msg.hwnd);
                if (dbl != null && !dbl.Enabled)
                {
                    break;
                }
                goto default;

            case Msg.WM_LBUTTONUP:
            case Msg.WM_RBUTTONUP:
            case Msg.WM_MBUTTONUP:
            case Msg.WM_XBUTTONUP:
                Control up = Control.FromHandle(msg.hwnd);
                if (up != null && !up.Enabled)
                {
                    break;
                }
                goto default;

            case Msg.WM_QUIT:
                quit = true;                         // make sure we exit
                break;

            default:
                if (PreTranslateMessage(ref msg))
                {
                    return((IntPtr)1);
                }

                XplatUI.TranslateMessage(ref msg);
                return(XplatUI.DispatchMessage(ref msg));
            }

            return(IntPtr.Zero);
        }
		public static object CallControlPointToScreen(Control c, object[] obj)
		{
			return c.PointToScreen((Point)obj[0]);
		}
Example #42
0
		void IChevron.Show(Control control, Point point)
		{
			ToolBarItemCollection chevronItems = new ToolBarItemCollection();
			Size size = ClientSize;
			int currentCount = 0;
			bool addItem = true;
			ToolBarItem lastItem;
			bool hasComboBox = false;

			for (int i = 0; i < items.Count; i++)
			{
				bool IsSeparator = false;
				RECT rect = new RECT();
				WindowsAPI.SendMessage(Handle, (int)ToolBarMessages.TB_GETITEMRECT, i, ref rect);
				if (rect.right > size.Width)
				{
					ToolBarItem item = items[i];
					if ( item.ComboBox != null )
						hasComboBox = true;
					IsSeparator = (item.Style == ToolBarItemStyle.Separator);
					if ( item.Visible )
						if ( (!IsSeparator ) || (chevronItems.Count != 0) )
						{
							// don't add it if previous item was a separator
							currentCount = chevronItems.Count;
							if ( currentCount > 0 )
							{
								lastItem = chevronItems[currentCount-1];
								if ( lastItem.Style == ToolBarItemStyle.Separator && IsSeparator )
								{
									addItem = false;
								}
							}

							if ( addItem )
								chevronItems.Add(item);
							addItem = true;
						}
				}
			}

			// Don't show a separator as the last item of the context menu
			int itemsCount = chevronItems.Count;
			if ( itemsCount > 0 )
			{
				lastItem = chevronItems[itemsCount-1];
				if ( lastItem.Style == ToolBarItemStyle.Separator )
					chevronItems.RemoveAt(itemsCount-1);
			}

			chevronMenu.Items = chevronItems;
			chevronMenu.Style = VisualStyle.IDE;
			chevronMenu.TrackPopup(control.PointToScreen(point));

			// Need to reparent the combobox to this toolbar in case
			// there was a combobox that was displayed by the popup menu
			if ( hasComboBox )
			{
				// Run the logic for combobox visibility before reposition it
				ToolbarSizeChanged();

				for (int i = 0; i < items.Count; i++)
				{
					ToolBarItem item = items[i];
					if ( item.Style == ToolBarItemStyle.ComboBox )
					{
						WindowsAPI.SetParent(item.ComboBox.Handle, Handle);
						ComboBoxBase cbb = (ComboBoxBase)item.ComboBox;
						cbb.ToolBarUse = true;
						UpdateItem(i);
						cbb.Invalidate();
					}
				}
			}
		}
Example #43
0
 /// <summary>
 ///     Create a screenshot relativ to a <see cref="Control"/> in a rectangle focus.
 /// </summary>
 /// <param name="ctrl">
 ///     Relativ to this <see cref="Control"/>.
 /// </param>
 /// <param name="screenshotArea">
 ///     Screenshot area.
 /// </param>
 /// <returns>
 ///     A <see cref="Bitmap"/> of the captured area.
 /// </returns>
 public static Bitmap CreateRelativeToControl(Control ctrl, Rectangle screenshotArea) {
     Point leftTopP = ctrl.PointToScreen(new Point(screenshotArea.Left, screenshotArea.Top));
     Rectangle r = new Rectangle(leftTopP.X + 1, leftTopP.Y + 1, screenshotArea.Width - 1, screenshotArea.Height - 1);
     Bitmap bmpScreen = ScreenShot.Create(r);
     return bmpScreen;
 }
Example #44
0
        // Returns true if the message should be dropped.
        internal static IntPtr SendMessage(ref MSG msg, out bool drop, out bool quit)
        {
            drop = false;
            quit = false;
            Message m = Message.Create(msg.hwnd, (int)msg.message, msg.wParam, msg.lParam);

            if (Application.FilterMessage(ref m))
            {
                drop = true;
                return(IntPtr.Zero);
            }

            switch ((Msg)msg.message)
            {
            case Msg.WM_KEYDOWN:
            case Msg.WM_SYSKEYDOWN:
            case Msg.WM_CHAR:
            case Msg.WM_SYSCHAR:
            case Msg.WM_KEYUP:
            case Msg.WM_SYSKEYUP:
                Control c = Control.FromHandle(msg.hwnd);

                // If we have a control with keyboard capture (usually a *Strip)
                // give it the message, and then drop the message
                if (keyboard_capture != null)
                {
                    // WM_SYSKEYUP does not make it into ProcessCmdKey, so do it here
                    if (msg.message == Msg.WM_SYSKEYDOWN)
                    {
                        if (m.WParam.ToInt32() == (int)Keys.Menu)
                        {
                            keyboard_capture.GetTopLevelToolStrip().Dismiss(ToolStripDropDownCloseReason.Keyboard);
                            drop = true;
                            return(IntPtr.Zero);
                        }
                    }

                    m.HWnd = keyboard_capture.Handle;

                    switch (keyboard_capture.PreProcessControlMessageInternal(ref m))
                    {
                    case PreProcessControlState.MessageProcessed:
                        drop = true;
                        return(IntPtr.Zero);

                    case PreProcessControlState.MessageNeeded:
                    case PreProcessControlState.MessageNotNeeded:
                        if (((msg.message == Msg.WM_KEYDOWN || msg.message == Msg.WM_CHAR) && keyboard_capture != null && !keyboard_capture.ProcessControlMnemonic((char)m.WParam)))
                        {
                            if (c == null || !ControlOnToolStrip(c))
                            {
                                drop = true;
                                return(IntPtr.Zero);
                            }
                            m.HWnd = msg.hwnd;
                        }
                        else
                        {
                            drop = true;
                            return(IntPtr.Zero);
                        }
                        break;
                    }
                }

                if (((c != null) && c.PreProcessControlMessageInternal(ref m) != PreProcessControlState.MessageProcessed) ||
                    (c == null))
                {
                    goto default;
                }
                return(new IntPtr(1));                        // Drop

            case Msg.WM_LBUTTONDOWN:
            case Msg.WM_MBUTTONDOWN:
            case Msg.WM_RBUTTONDOWN:
                if (keyboard_capture != null)
                {
                    Control c2 = Control.FromHandle(msg.hwnd);

                    // The target is not a winforms control (an embedded control, perhaps), so
                    // release everything
                    if (c2 == null)
                    {
                        ToolStripManager.FireAppClicked();
                        goto default;
                    }

                    // Skip clicks on owner windows, eg. expanded ComboBox
                    if (Control.IsChild(keyboard_capture.Handle, msg.hwnd))
                    {
                        goto default;
                    }

                    // Close any active toolstrips drop-downs if we click outside of them,
                    // but also don't close them all if we click outside of the top-most
                    // one, but into its owner.
                    Point c2_point = c2.PointToScreen(new Point(
                                                          (int)(short)(m.LParam.ToInt32() & 0xffff),
                                                          (int)(short)(m.LParam.ToInt32() >> 16)));
                    while (keyboard_capture != null && !keyboard_capture.ClientRectangle.Contains(keyboard_capture.PointToClient(c2_point)))
                    {
                        keyboard_capture.Dismiss();
                    }
                }
                goto default;

            case Msg.WM_QUIT:
                quit = true;                         // make sure we exit
                break;

            default:
                XplatUI.TranslateMessage(ref msg);
                return(XplatUI.DispatchMessage(ref msg));
            }

            return(IntPtr.Zero);
        }
 private void ShowClipboardCopiedLabel(Control control)
 {
     var screenCoord = control.PointToScreen(Point.Empty);
     var controlLoc = PointToClient(screenCoord);
     toolTip2.Show("Copied to clipboard!", this, controlLoc, 2000);
 }
Example #46
0
        // Show this context menu at the specified control-relative co-ordinates.
        public void Show(Control control, Point pos)
        {
            associatedControl = control;
            currentMouseItem  = -1;    // Not over anything
            popupControl      = new PopupControl();
            // We need the following events from popupControl.
            popupControl.MouseMove += new MouseEventHandler(OnMouseMove);
            popupControl.MouseDown += new MouseEventHandler(OnMouseDown);
            popupControl.Paint     += new PaintEventHandler(popupControl_Paint);

            OnPopup(EventArgs.Empty);

            // Figure out where we need to put the popup and its size.
            Point     pt     = control.PointToScreen(new Point(0, 0));
            Rectangle rcWork = Screen.PrimaryScreen.WorkingArea;

            using (Graphics g = popupControl.CreateGraphics())
            {
                Size size = MeasureItemBounds(g);
                size.Height -= 1;
                //align it to control
                if (pt.X < rcWork.Left)
                {
                    pt.X += size.Width;
                }
                if (pt.X > rcWork.Right - size.Width)
                {
                    pt.X -= size.Width;
                }
                if (pt.Y < rcWork.Top)
                {
                    pt.Y += size.Height;
                }
                if (pt.Y > rcWork.Bottom - size.Height)
                {
                    pt.Y -= size.Height;
                }
                //add offset pos
                pt.X += pos.X;
                pt.Y += pos.Y;
                //ensure that it is completely visible on screen
                if (pt.X < rcWork.Left)
                {
                    pt.X = rcWork.Left;
                }
                if (pt.X > rcWork.Right - size.Width)
                {
                    pt.X = rcWork.Right - size.Width;
                }
                if (pt.Y < rcWork.Top)
                {
                    pt.Y = rcWork.Top;
                }
                if (pt.Y > rcWork.Bottom + size.Height)
                {
                    pt.Y = rcWork.Bottom - size.Height;
                }
                popupControl.Bounds = new Rectangle(pt, size);
            }
            popupControl.Show();
        }
Example #47
0
        private static bool _ProcessControl(PointF mousePosition, Control control, bool ignore_rect)
        {
            // ignore_rect will call mouse_up & mouse_move in any case.
            var c_location = control.PointToScreen(System.Drawing.Point.Empty);
            var clientRect = new System.Drawing.RectangleF(c_location.X, c_location.Y, control.Width, control.Height);
            var contains   = clientRect.Contains(mousePosition);

            if (contains && (mouseEvent == MouseEvents.Down) || mouseEvent == MouseEvents.Up)
            {
                if (control.Parent != null)
                {
                    bool ok             = true;
                    var  clickedControl = _ParentContains(control, mousePosition, control, ref ok);
                    if (clickedControl != null && ok == false)
                    {
                        control = clickedControl;
                    }
                }
            }

            if (ignore_rect || contains)
            {
                var client_mpos = control.PointToClient(new Point((int)mousePosition.X, (int)mousePosition.Y));
                if (mousePositionChanged)
                {
                    if (dragData != null)
                    {
                        dragndrop = true;
                    }
                }

                if (!contains && mouseEvent != MouseEvents.Up)
                {
                    return(true);
                }
                switch (mouseEvent)
                {
                case MouseEvents.Down:
                    var md_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseDown(md_args);
                    mouseLastClickControl = control;
                    return(true);

                case MouseEvents.Up:
                    if (dragndrop)
                    {
                        if (control.AllowDrop)
                        {
                            DataObject    dnd_data = new DataObject(dragData);
                            DragEventArgs dnd_args = new DragEventArgs(dnd_data, 0, (int)client_mpos.X, (int)client_mpos.Y, DragDropEffects.None, dragControlEffects);
                            control.RaiseOnDragDrop(dnd_args);
                        }
                        dragData  = null;
                        dragndrop = false;
                        return(true);
                    }
                    var mu_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseUp(mu_args);
                    if (mouseLastClickControl == control)
                    {
                        control.RaiseOnMouseClick(mu_args);
                    }
                    if (mouseLastClickControl != null && control != mouseLastClickControl)
                    {
                        mouseLastClickControl.RaiseOnMouseUp(mu_args);
                    }
                    return(true);

                case MouseEvents.DoubleClick:
                    var mdc_args = new MouseEventArgs(mouseButton, 2, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseDoubleClick(mdc_args);
                    return(true);

                case MouseEvents.Wheel:
                    var mw_args = new MouseEventArgs(MouseButtons.Middle, 0, (int)client_mpos.X, (int)client_mpos.Y, (int)(-mouseWheelDelta * 4));
                    control.RaiseOnMouseWheel(mw_args);
                    return(true);
                }
            }
            if (!contains)
            {
                control.RaiseOnMouseLeave(null);
            }
            return(false);
        }
Example #48
0
        public void Show(Control control, Rectangle rect, bool center)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            SetOwnerItem(control);

            if (_canResize && !_changeRegion)
            {
                Padding = new Padding(3);
            }
            else if (!_changeRegion)
            {
                Padding = new Padding(1);
            }
            else
            {
                Padding = Padding.Empty;
            }

            int width  = Padding.Horizontal;
            int height = Padding.Vertical;

            base.Size = new Size(_popupControl.Width + width, _popupControl.Height + height);

            _resizableTop  = false;
            _resizableLeft = false;
            Point     location = control.PointToScreen(new Point(rect.Left, rect.Bottom));
            Rectangle screen   = Screen.FromControl(control).WorkingArea;

            if (center)
            {
                if (location.X + (rect.Width + Size.Width) / 2 > screen.Right)
                {
                    location.X     = screen.Right - Size.Width;
                    _resizableLeft = true;
                }
                else
                {
                    location.X = location.X - (Size.Width - rect.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 + rect.Height;
            }

            location = control.PointToClient(location);
            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }