当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.Contains方法代码示例

本文整理汇总了C#中System.Drawing.Rectangle.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Contains方法的具体用法?C# Rectangle.Contains怎么用?C# Rectangle.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Rectangle的用法示例。


在下文中一共展示了Rectangle.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawBackgroundImage

 public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (backgroundImageLayout == ImageLayout.Tile)
     {
         using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
         {
             if (scrollOffset != Point.Empty)
             {
                 Matrix transform = brush.Transform;
                 transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y);
                 brush.Transform = transform;
             }
             g.FillRectangle(brush, clipRect);
             return;
         }
     }
     Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
     if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
     {
         rect.X += clipRect.Width - rect.Width;
     }
     using (SolidBrush brush2 = new SolidBrush(backColor))
     {
         g.FillRectangle(brush2, clipRect);
     }
     if (!clipRect.Contains(rect))
     {
         if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
         {
             rect.Intersect(clipRect);
             g.DrawImage(backgroundImage, rect);
         }
         else if (backgroundImageLayout == ImageLayout.None)
         {
             rect.Offset(clipRect.Location);
             Rectangle destRect = rect;
             destRect.Intersect(clipRect);
             Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
             g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
         }
         else
         {
             Rectangle rectangle4 = rect;
             rectangle4.Intersect(clipRect);
             Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
             g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
         }
     }
     else
     {
         ImageAttributes imageAttr = new ImageAttributes();
         imageAttr.SetWrapMode(WrapMode.TileFlipXY);
         g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
         imageAttr.Dispose();
     }
 }
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:60,代码来源:CmbControlPaintEx.cs

示例2: pnlPointEditor_MouseUp

		private void pnlPointEditor_MouseUp(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right) {
				if (mPoints.Count > 0) {
					mPoints.RemoveAt(mPoints.Count - 1);
					RefreshPoints();
				}

				return;
			}


			if (IsComplete())
				return;

			//Check if its near first point
			if (mPoints.Count > 1) {
				Point p = mPoints[0];
				Rectangle area = new Rectangle(p.X - 2, p.Y - 2, 4, 4);
				if (area.Contains(e.X, e.Y)) {
					mPoints.Add(p);
					RefreshPoints();
					return;
				}
			}

			mPoints.Add(new Point(e.X, e.Y));

			RefreshPoints();
		}
开发者ID:Megamatt01,项目名称:peggle-edit,代码行数:30,代码来源:PolygonEditor.cs

示例3: OnMouseDown

 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (!DesignMode)
     {
         if (this.TabCount > 0)
         {
             // Test if the user clicked a close button
             Point loc = new Point(e.Location.X, e.Location.Y % this.ItemSize.Height + (this.RowCount - 1) * this.ItemSize.Height);
             Rectangle standardArea = Rectangle.Empty, closeBtnArea = Rectangle.Empty;
             for (int nIndex = 0; nIndex < this.TabCount; nIndex++)
             {
                 standardArea = this.GetTabRect(nIndex);
                 closeBtnArea = new Rectangle(standardArea.Right - 15, standardArea.Top + 3, 12, standardArea.Height - 6);
                 if (closeBtnArea.Contains(loc))
                 {
                     // Close the tabpage if the user confirms the action
                     if (MessageBox.Show("You are about to close " + this.TabPages[nIndex].Text.TrimEnd() +
                             " tab. Are you sure you want to continue?", "Confirm close", MessageBoxButtons.YesNo) == DialogResult.No)
                         return;
                     if (this.SelectedIndex == nIndex && this.SelectedIndex + 1 < this.TabCount) this.SelectedIndex++;
                     this.TabPages.RemoveAt(nIndex);
                     if (this.TabCount == 0) this.Visible = false;
                     hoveringIndex = -1;
                     // Fire close event
                     if (OnClose != null)
                     {
                         OnClose(this, new EventArgs());
                     }
                 }
             }
         }
     }
 }
开发者ID:Artenuvielle,项目名称:PatternAnalyzer,代码行数:33,代码来源:StyledTabControll.cs

示例4: ConstrainToBounds

 internal static Rectangle ConstrainToBounds(Rectangle constrainingBounds, Rectangle bounds)
 {
     if (!constrainingBounds.Contains(bounds))
     {
         bounds.Size = new Size(Math.Min(constrainingBounds.Width - 2, bounds.Width), Math.Min(constrainingBounds.Height - 2, bounds.Height));
         if (bounds.Right > constrainingBounds.Right)
         {
             bounds.X = constrainingBounds.Right - bounds.Width;
         }
         else if (bounds.Left < constrainingBounds.Left)
         {
             bounds.X = constrainingBounds.Left;
         }
         if (bounds.Bottom > constrainingBounds.Bottom)
         {
             bounds.Y = (constrainingBounds.Bottom - 1) - bounds.Height;
             return bounds;
         }
         if (bounds.Top < constrainingBounds.Top)
         {
             bounds.Y = constrainingBounds.Top;
         }
     }
     return bounds;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:WindowsFormsUtils.cs

示例5: Paint

        protected override void Paint(
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates cellState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // Call the base class method to paint the default cell appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                value, formattedValue, errorText, cellStyle,
                advancedBorderStyle, paintParts);

            // Retrieve the client location of the mouse pointer.
            Point cursorPosition =
                this.DataGridView.PointToClient(Cursor.Position);

            // If the mouse pointer is over the current cell, draw a custom border.
            if (cellBounds.Contains(cursorPosition))
            {
                Rectangle newRect = new Rectangle(cellBounds.X + 1,
                    cellBounds.Y + 1, cellBounds.Width - 4,
                    cellBounds.Height - 4);
                graphics.DrawRectangle(Pens.Red, newRect);
            }
        }
开发者ID:romanu6891,项目名称:fivemen,代码行数:31,代码来源:DataGridViewRolloverCell.cs

示例6: AutoScrollDirectionFromPoint

 private ScrollDirection AutoScrollDirectionFromPoint(Point clientPoint)
 {
     Rectangle rectangle = new Rectangle(Point.Empty, base.ParentView.ViewPortSize);
     if (!rectangle.Contains(clientPoint))
     {
         return ScrollDirection.None;
     }
     ScrollDirection none = ScrollDirection.None;
     ScrollBar hScrollBar = base.ParentView.HScrollBar;
     if ((clientPoint.X <= (rectangle.Width / 10)) && (hScrollBar.Value > 0))
     {
         none |= ScrollDirection.Left;
     }
     else if ((clientPoint.X >= (rectangle.Right - (rectangle.Width / 10))) && (hScrollBar.Value < (hScrollBar.Maximum - hScrollBar.LargeChange)))
     {
         none |= ScrollDirection.Right;
     }
     ScrollBar vScrollBar = base.ParentView.VScrollBar;
     if ((clientPoint.Y <= (rectangle.Height / 10)) && (vScrollBar.Value > 0))
     {
         return (none | ScrollDirection.Up);
     }
     if ((clientPoint.Y >= (rectangle.Bottom - (rectangle.Height / 10))) && (vScrollBar.Value < (vScrollBar.Maximum - vScrollBar.LargeChange)))
     {
         none |= ScrollDirection.Down;
     }
     return none;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:AutoScrollingMessageFilter.cs

示例7: MoveFormAwayFromSelection

        // This was taken from FindReplaceDialog. Obviously some refactoring is called for
        // since we have common code. However I'm holding off on this because I'm coming
        // up with some other ideas for the FindReplaceDialog. Right now every scintilla
        // gets its own FindReplaceDialog, but they really need to be sharable across 
        // multiple scintillas much like how DropMarkers work.

        private void MoveFormAwayFromSelection()
        {
            if (!Visible)
                return;

            int pos = Scintilla.Caret.Position;
            int x = Scintilla.PointXFromPosition(pos);
            int y = Scintilla.PointYFromPosition(pos);

            Point cursorPoint = Scintilla.PointToScreen(new Point(x, y));

            Rectangle r = new Rectangle(Location, Size);
            if (r.Contains(cursorPoint))
            {
                Point newLocation;
                if (cursorPoint.Y < (Screen.PrimaryScreen.Bounds.Height / 2))
                {
                    // Top half of the screen
                    newLocation = Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y + Scintilla.Lines.Current.Height * 2)
                        );
                }
                else
                {
                    // Bottom half of the screen
                    newLocation = Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y - Height - (Scintilla.Lines.Current.Height * 2))
                        );
                }
                newLocation = Scintilla.PointToScreen(newLocation);
                Location = newLocation;
            }
        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:39,代码来源:GoToDialog.cs

示例8: Contains

        public bool Contains(Point p)
        {
            Rectangle draw_rect = new Rectangle(Position.Location, new Size(4, 4));
            draw_rect.Offset(-2, -2);

            return draw_rect.Contains(p);
        }
开发者ID:whoo24,项目名称:geometry_tool_on_csharp,代码行数:7,代码来源:PointObject.cs

示例9: Find

        public Point? Find(Bitmap findBitmap)
        {
            if (sourceImage == null || findBitmap == null)
                throw new InvalidOperationException();

            findImage = new ImageData(findBitmap);
            findImage.PixelMaskTable(this.Variation);

            var SourceRect = new Rectangle(new Point(0, 0), sourceImage.Size);
            var NeedleRect = new Rectangle(new Point(0, 0), findImage.Size);

            if (SourceRect.Contains(NeedleRect))
            {
                resets = new ManualResetEvent[threads];
                Provider = new CoordProvider(sourceImage.Size, NeedleRect.Size);

                for (int i = 0; i < threads; i++)
                {
                    resets[i] = new ManualResetEvent(false);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ImageWorker), i);
                }

                WaitHandle.WaitAll(resets);

                return match;
            }

            return null;
        }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:29,代码来源:ImageFinder.cs

示例10: moveFormAwayFromSelection

        public void moveFormAwayFromSelection()
        {
            if (!Visible || this.Scintilla == null)
                return;

            int pos = this.Scintilla.Caret.Position;
            int x = this.Scintilla.PointXFromPosition(pos);
            int y = this.Scintilla.PointYFromPosition(pos);

            var cursorPoint = new Point(x, y);

            var r = new Rectangle(Location, Size);
            if (r.Contains(cursorPoint))
            {
                Point newLocation;
                if (cursorPoint.Y < (Screen.PrimaryScreen.Bounds.Height / 2))
                {
                    // Top half of the screen
                    newLocation = new Point(Location.X, cursorPoint.Y + this.Scintilla.Lines.Current.Height * 2);

                }
                else
                {
                    // FixedY half of the screen
                    newLocation = new Point(Location.X, cursorPoint.Y - Height - (this.Scintilla.Lines.Current.Height * 2));
                }

                Location = newLocation;
            }
        }
开发者ID:borisblizzard,项目名称:arcreator,代码行数:30,代码来源:IncrementalSearcher.cs

示例11: Form1_KeyDown

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Left)
            {
                pictureBox1.Left -= 10;
            }
            if (e.KeyData == Keys.Right)
            {
                pictureBox1.Left += 10;
            }
            if (e.KeyData == Keys.Up)
            {
                pictureBox1.Top -= 10;
            }
            if (e.KeyData == Keys.Down)
            {
                pictureBox1.Top += 10;
            }
             Rectangle dropRect = new Rectangle(200, 100, 350, 250);
            isDragging = false;
            if (dropRect.Contains(pictureBox1.Bounds))
            { SoundPlayer player = new SoundPlayer();
                player.SoundLocation = @"C:\Users\admin\Music\tada.wav";
                player.Play();
                MessageBox.Show("Вы победили!", "Проверка попадания");

            }
        }
开发者ID:VladimirTsy,项目名称:Party,代码行数:28,代码来源:Form1.cs

示例12: IsObjectInArea

        public bool IsObjectInArea(Rectangle area)
        {
            Rectangle ImageArea = new Rectangle(Map.Instance.CenterX + Object.GetInt("x") - ((Object.GetBool("f")) ? Image.GetCanvas().width - Image.GetVector("origin").x : Image.GetVector("origin").x), Map.Instance.CenterY + Object.GetInt("y") - Image.GetVector("origin").y, Image.GetCanvas().width, Image.GetCanvas().height);
            if (ImageArea.Contains(area)) return true;
            Rectangle common = Rectangle.Intersect(ImageArea, area);
            if (common != Rectangle.Empty)
            {
                if (common.Contains(lastKnown)) return true;
                Bitmap b = (Object.GetBool("f")) ? Image.GetCanvas().GetFlippedBitmap() : Image.GetCanvas().GetBitmap();

                bool toSwitchX = MapEditor.Instance.selectingX > common.X;
                bool toSwitchY = MapEditor.Instance.selectingY > common.Y;
                for (int x = toSwitchX ? common.X - ImageArea.X + common.Width - 1 : common.X - ImageArea.X; toSwitchX ? x >= common.X - ImageArea.X : x < common.X - ImageArea.X + common.Width; x += toSwitchX ? -1 : 1)
                {
                    for (int y = toSwitchY ? common.Y - ImageArea.Y + common.Height - 1 : common.Y - ImageArea.Y; toSwitchY ? y >= common.Y - ImageArea.Y : y < common.Y - ImageArea.Y + common.Height; y += toSwitchY ? -1 : 1)
                    {
                        if (b.GetPixel(x, y).A > 0)
                        {
                            lastKnown = new Point(x + ImageArea.X, y + ImageArea.Y);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
开发者ID:smolson4,项目名称:wzmapeditor,代码行数:26,代码来源:MapLife.cs

示例13: MergeCells

        //ExStart
        //ExId:MergeCellsMethod
        //ExSummary:A method which merges all cells of a table in the specified range of cells.
        /// <summary>
        /// Merges the range of cells found between the two specified cells both horizontally and vertically. Can span over multiple rows.
        /// </summary>
        public static void MergeCells(Cell startCell, Cell endCell)
        {
            Table parentTable = startCell.ParentRow.ParentTable;

            // Find the row and cell indices for the start and end cell.
            Point startCellPos = new Point(startCell.ParentRow.IndexOf(startCell), parentTable.IndexOf(startCell.ParentRow));
            Point endCellPos = new Point(endCell.ParentRow.IndexOf(endCell), parentTable.IndexOf(endCell.ParentRow));
            // Create the range of cells to be merged based off these indices. Inverse each index if the end cell if before the start cell.
            Rectangle mergeRange = new Rectangle(Math.Min(startCellPos.X, endCellPos.X), Math.Min(startCellPos.Y, endCellPos.Y),
                Math.Abs(endCellPos.X - startCellPos.X) + 1, Math.Abs(endCellPos.Y - startCellPos.Y) + 1);

            foreach (Row row in parentTable.Rows)
            {
                foreach (Cell cell in row.Cells)
                {
                    Point currentPos = new Point(row.IndexOf(cell), parentTable.IndexOf(row));

                    // Check if the current cell is inside our merge range then merge it.
                    if (mergeRange.Contains(currentPos))
                    {
                        if (currentPos.X == mergeRange.X)
                            cell.CellFormat.HorizontalMerge = CellMerge.First;
                        else
                            cell.CellFormat.HorizontalMerge = CellMerge.Previous;

                        if (currentPos.Y == mergeRange.Y)
                            cell.CellFormat.VerticalMerge = CellMerge.First;
                        else
                            cell.CellFormat.VerticalMerge = CellMerge.Previous;
                    }
                }
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:39,代码来源:ExTable.cs

示例14: PopupWindow

        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
        }
开发者ID:slgrobotics,项目名称:QuakeMap,代码行数:29,代码来源:PopupWindow.cs

示例15: MouseDownEventHandler

        protected virtual void MouseDownEventHandler(object sender, MouseEventArgs e)
        {
            Point first_one = this.PointToClient(Cursor.Position);

              #region Rectangles

              Rectangle rectYSol = new Rectangle(((TextBox)sender).Location.X, ((TextBox)sender).Location.Y, 10, 10);
              Rectangle rectYSag = new Rectangle(((TextBox)sender).Location.X + ((TextBox)sender).Width - 11, ((TextBox)sender).Location.Y, 10, 10);
              Rectangle rectASol = new Rectangle(((TextBox)sender).Location.X, ((TextBox)sender).Location.Y + ((TextBox)sender).Height - 11, 10, 10);
              Rectangle rectASag = new Rectangle(((TextBox)sender).Location.X + ((TextBox)sender).Width - 11, ((TextBox)sender).Location.Y + ((TextBox)sender).Height - 11, 10, 10);

              #endregion

              if (e.Button == MouseButtons.Left)
              {
            x_offset = ((TextBox)sender).Location.X;
            y_offset = ((TextBox)sender).Location.Y;
            if (rectYSol.Contains(first_one))
            {
              YSol = true;
              Cursor = Cursors.PanNW;
              YSol_offset_x = e.X;
              YSol_offset_y = e.Y;
              storedOposite.X = ((TextBox)sender).Location.X + ((TextBox)sender).Width;
              storedOposite.Y = ((TextBox)sender).Location.Y + ((TextBox)sender).Height;
            }
            else if (rectYSag.Contains(first_one))
            {
              YSag = true;
              Cursor = Cursors.PanNE;
              YSag_offset_x = ((TextBox)sender).Width - e.X;
              YSag_offset_y = e.Y;
              storedOposite.X = ((TextBox)sender).Location.X;
              storedOposite.Y = ((TextBox)sender).Location.Y + ((TextBox)sender).Height;
            }
            else if (rectASol.Contains(first_one))
            {
              ASol = true;
              Cursor = Cursors.PanSW;
              ASol_offset_x = e.X;
              ASol_offset_y = ((TextBox)sender).Width - e.Y;
              storedOposite.X = ((TextBox)sender).Location.X + ((TextBox)sender).Width;
              storedOposite.Y = ((TextBox)sender).Location.Y;
            }
            else if (rectASag.Contains(first_one))
            {
              ASag = true;
              Cursor = Cursors.PanSE;
              ASag_offset_x = ((TextBox)sender).Width - e.X;
              ASag_offset_y = ((TextBox)sender).Width - e.X;
            }
            else
            {
              O_offset_x = e.X;
              O_offset_y = e.Y;
            }

              }
        }
开发者ID:swoopertr,项目名称:KesSu,代码行数:59,代码来源:Print_Dizayn.cs


注:本文中的System.Drawing.Rectangle.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。