コード例 #1
0
        /// <summary>
        /// 是否在Button按钮区域
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        protected bool IsInRegion(Point p, int columnIndex, int rowIndex)
        {
            Rectangle cellBounds = DataGridView[columnIndex, rowIndex].ContentBounds;

            RectangleCommon.GetSmallRectOfRectangle(cellBounds, this.Size, out this.m_absBtnRegion);
            return(this.m_absBtnRegion.Contains(p));
        }
コード例 #2
0
        /// <summary>
        /// 鼠标捕获期间绘制可逆图形的回调处理
        /// </summary>
        protected virtual void OnReversibleDrawCallback()
        {
            System.Drawing.Rectangle rect = RectangleCommon.GetRectangle(this.myStartPosition, this.myCurrentPosition);
            switch (intReversibleShape)
            {
            case ReversibleShapeStyle.Line:
                System.Windows.Forms.ControlPaint.DrawReversibleLine(this.myStartPosition, this.myCurrentPosition, System.Drawing.Color.Black);
                break;

            case ReversibleShapeStyle.Rectangle:
                System.Windows.Forms.ControlPaint.DrawReversibleFrame(rect, System.Drawing.Color.SkyBlue, System.Windows.Forms.FrameStyle.Dashed);
                break;

            case ReversibleShapeStyle.FillRectangle:
                System.Windows.Forms.ControlPaint.FillReversibleRectangle(rect, System.Drawing.Color.Black);
                break;

            case ReversibleShapeStyle.Custom:
                if (Draw != null)
                {
                    Draw(this, null);
                }
                break;
            }
        }
コード例 #3
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //此段代码主要解决xp下,如果鼠标默认在按钮列上,按钮的默认绘制样式问题

            if (this.m_firstDraw)
            {
                this.m_firstDraw   = false;
                this.m_curBtnState = this.Enabled ? PushButtonState.Normal : PushButtonState.Disabled;
            }
            // 是否需要重绘单元格的背景颜色
            m_brushCellBack = this.DataGridView.SelectedCells.Contains(this) ?
                              new SolidBrush(cellStyle.SelectionBackColor) : new SolidBrush(cellStyle.BackColor);
            graphics.FillRectangle(m_brushCellBack, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height);

            //计算button的区域
            m_buttonRegion = RectangleCommon.GetSmallRectOfRectangle(cellBounds, this.Size, out this.m_absBtnRegion);

            //绘制按钮
            if (m_enabled)
            {
                this.InternalDrawButton(graphics, m_buttonRegion, m_curBtnState, Text);
            }
            else
            {
                this.InternalDrawButton(graphics, m_buttonRegion, PushButtonState.Disabled, Text);
            }

            // 填充单元格的边框
            base.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
        }
コード例 #4
0
        public System.Drawing.PointF AbsUnTransformPoint(float x, float y)
        {
            SimpleRectangleTransform pre  = null;
            SimpleRectangleTransform next = null;
            SimpleRectangleTransform cur  = null;

            foreach (SimpleRectangleTransform item in this)
            {
                if (item.Enable == false)
                {
                    continue;
                }
                if (intLimitedPageIndex >= 0 && item.PageIndex != intLimitedPageIndex)
                {
                    continue;
                }
                if (item.DescRectF.Contains(x, y))
                {
                    return(item.UnTransformPointF(x, y));
                }

                if (y >= item.DescRectF.Top && y < item.DescRectF.Bottom)
                {
                    cur = item;
                    break;
                }
                if (y < item.DescRectF.Top)
                {
                    if (next == null || item.DescRectF.Top < next.DescRectF.Top)
                    {
                        next = item;
                    }
                }
                if (y > item.DescRectF.Bottom)
                {
                    if (pre == null || item.DescRectF.Bottom > pre.DescRectF.Bottom)
                    {
                        pre = item;
                    }
                }
            }//foreach
            if (cur == null)
            {
                if (pre != null)
                {
                    cur = pre;
                }
                else
                {
                    cur = next;
                }
            }
            if (cur == null)
            {
                return(System.Drawing.PointF.Empty);
            }
            System.Drawing.PointF p = new System.Drawing.PointF(x, y);
            p = RectangleCommon.MoveInto(p, cur.DescRectF);
            return(cur.UnTransformPointF(p));
        }
コード例 #5
0
 private System.Drawing.Point GetMousePosition(System.Drawing.Point p)
 {
     if (myBindControl != null)
     {
         p = myBindControl.PointToClient(p);
     }
     return(RectangleCommon.MoveInto(p, this.myClipRectangle));
 }
コード例 #6
0
        public static System.Drawing.Drawing2D.Matrix RotateGraphics(
            System.Drawing.Graphics g,
            System.Drawing.Rectangle Bounds,
            float Angle)
        {
            //			System.Drawing.Point cp = RectangleCommon.Center( Bounds );
            //			System.Drawing.Rectangle rect = new System.Drawing.Rectangle (
            //				cp.X - ContentBounds.Width / 2 ,
            //				cp.Y - ContentBounds.Height / 2 ,
            //				ContentBounds.Width ,
            //				ContentBounds.Height );


            System.Drawing.Drawing2D.Matrix om = g.Transform;
            System.Drawing.Drawing2D.Matrix nm = om.Clone();
            System.Drawing.Point            p  = RectangleCommon.Center(Bounds);
            nm.RotateAt(Angle, new System.Drawing.PointF(p.X, p.Y));
            g.Transform = nm;
            return(om);
        }
コード例 #7
0
        /// <summary>
        /// 根据转换后的坐标位置查找转换信息对象
        /// </summary>
        /// <param name="x">点X坐标</param>
        /// <param name="y">点Y坐标</param>
        /// <param name="compatibility">是否启用兼容模式。若启用兼容模式,
        /// 如果没有找到和指定点精确匹配的坐标转换信息对象,
        /// 则尽量查找距离点最近的坐标转换信息对象</param>
        /// <param name="onlyIncludeEnabledItem">只对可用的对象进行处理</param>
        /// <param name="useSourceRect">模式,True:匹配源矩形;False:匹配目标矩形。</param>
        /// <returns>找到的坐标转换信息对象</returns>
        public SimpleRectangleTransform GetItemByPoint(
            float x,
            float y,
            bool useSourceRect,
            bool compatibility,
            bool onlyIncludeEnabledItem)
        {
            if (this.Count == 0)
            {
                // 列表为空,没法获得值
                return(null);
            }
            foreach (SimpleRectangleTransform item in this.myItems)
            {
                if (onlyIncludeEnabledItem && item.Enable == false)
                {
                    continue;
                }

                if (useSourceRect)
                {
                    if (item.SourceRectF.Contains(x, y))
                    {
                        return(item);
                    }
                }
                else
                {
                    if (item.DescRectF.Contains(x, y))
                    {
                        return(item);
                    }
                }
            }//foreach
            if (compatibility)
            {
                // 寻找距离最近的目标矩形区域
                float minLen = 0;
                int   index  = 0;
                for (int iCount = 0; iCount < this.myItems.Count; iCount++)
                {
                    SimpleRectangleTransform item = myItems[iCount];
                    if (onlyIncludeEnabledItem && item.Enable == false)
                    {
                        continue;
                    }

                    RectangleF rect = useSourceRect ? item.SourceRectF : item.DescRectF;
                    if (rect.Contains(x, y))
                    {
                        return(myItems[iCount]);
                    }
                    float len = RectangleCommon.GetDistance(x, y, rect);
                    if (iCount == 0 || len < minLen)
                    {
                        minLen = len;
                        index  = iCount;
                    }
                }//for
                return(myItems[index]);
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
 protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, @"", @"", errorText, cellStyle, advancedBorderStyle, paintParts);
     this.m_chkboxRegion = RectangleCommon.GetSmallRectOfRectangle(cellBounds, CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal), out m_absChkboxRegion);
     this.RenderCheckBox(graphics);
 }