private void ShiftingSplitter()
        {
            GridViewInfo viewInfo         = gridViewPanel1.GetViewInfo() as GridViewInfo;
            int          splitterPosition = 0;

            height = viewInfo.ViewRects.ColumnPanel.Bottom + 2;
            if (viewInfo.GetGridRowInfo(GridControl.AutoFilterRowHandle) != null)
            {
                height += viewInfo.CalcRowHeight(viewInfo.GInfo.Graphics, GridControl.AutoFilterRowHandle, -1, 0) + 4;
            }
            splitterPosition = height;
            Dictionary <int, int> .ValueCollection values = FixedRows.Values;
            for (int i = 0; i < values.Count; i++)
            {
                height += values.ToArray()[i] + 1;
            }
            splitterPosition = Math.Max(height, splitterPosition);
            if (splitterPosition >= viewInfo.ViewRects.EmptyRows.Bottom)
            {
                splitterPosition -= viewInfo.ViewRects.EmptyRows.Height;
            }
            gridSplitContainer1.SplitterPosition = splitterPosition;
            splitterPosition -= viewInfo.ViewRects.EmptyRows.Bottom - viewInfo.ViewRects.EmptyRows.Top;
            if (viewInfo.ViewRects.EmptyRows.Top != 0)
            {
                gridSplitContainer1.SplitterPosition = splitterPosition;
            }
        }
Exemplo n.º 2
0
        void OnMouseMove(object sender, MouseEventArgs e)
        {
            GridHitInfo hitInfo = view.CalcHitInfo(e.Location);

            if (hitInfo.HitTest == GridHitTest.Row && view.IsGroupRow(hitInfo.RowHandle))
            {
                GridViewInfo       viewInfo = view.GetViewInfo() as GridViewInfo;
                GridGroupRowInfo   rowInfo  = viewInfo.GetGridRowInfo(hitInfo.RowHandle) as GridGroupRowInfo;
                GridColumn         col      = viewInfo.GetNearestColumn(e.Location);
                GridColumnInfoArgs args     = viewInfo.ColumnsInfo[col];
                if (col.VisibleIndex == 0)
                {
                    HotTrackRectangle = new Rectangle(rowInfo.ButtonBounds.Right + 2, rowInfo.Bounds.Y,
                                                      args.Bounds.Width + args.Bounds.X - rowInfo.ButtonBounds.Right - 2, rowInfo.Bounds.Height);
                }
                else
                {
                    HotTrackRectangle = new Rectangle(args.Bounds.X + 2, rowInfo.Bounds.Y,
                                                      args.Bounds.Width - 2, rowInfo.Bounds.Height);
                }
            }
            else
            {
                HotTrackRectangle = Rectangle.Empty;
            }
        }
        private void grid_Paint(object sender, PaintEventArgs e)
        {
            if (DropTargetRowHandle < 0)
            {
                return;
            }
            GridControl  grid         = (GridControl)sender;
            GridView     view         = (GridView)grid.MainView;
            bool         isBottomLine = DropTargetRowHandle == view.DataRowCount;
            GridViewInfo viewInfo     = view.GetViewInfo() as GridViewInfo;
            GridRowInfo  rowInfo      = viewInfo.GetGridRowInfo(isBottomLine ? DropTargetRowHandle - 1 : DropTargetRowHandle);

            if (rowInfo == null)
            {
                return;
            }
            Point p1, p2;

            if (isBottomLine)
            {
                p1 = new Point(rowInfo.Bounds.Left, rowInfo.Bounds.Bottom - 1);
                p2 = new Point(rowInfo.Bounds.Right, rowInfo.Bounds.Bottom - 1);
            }
            else
            {
                p1 = new Point(rowInfo.Bounds.Left, rowInfo.Bounds.Top - 1);
                p2 = new Point(rowInfo.Bounds.Right, rowInfo.Bounds.Top - 1);
            }
            e.Graphics.DrawLine(Pens.Blue, p1, p2);
        }
        public Cursor GetDragCursor(int rowHandle, Point e)
        {
            GridViewInfo info    = _view.GetViewInfo() as GridViewInfo;
            GridRowInfo  rowInfo = info.GetGridRowInfo(rowHandle);
            Bitmap       result  = GetRowDragBitmap(rowHandle);
            Point        offset  = new Point(rowInfo.Bounds.X, e.Y - rowInfo.Bounds.Y);

            return(CursorCreator.CreateCursor(result, offset));
        }
        private void gridView1_BeforePrintRow(object sender, DevExpress.XtraGrid.Views.Printing.CancelPrintRowEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (!(sender is GridView))
                {
                    return;
                }
                GridView    gridView = ((GridView)sender);
                DataRowView dataRow  = gridView.GetRow(e.RowHandle) as DataRowView;
                if (dataRow == null)
                {
                    return;
                }

                if ((bool)dataRow["Name6"])
                {
                    GridViewInfo      vi        = (GridViewInfo)gridView.GetViewInfo();
                    PropertyInfo      pi        = typeof(BaseView).GetProperty("PrintInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                    GridViewPrintInfo printInfo = (GridViewPrintInfo)pi.GetValue(gridView, null);


                    GridRowInfo gridRowInfo    = vi.GetGridRowInfo(e.RowHandle);
                    SizeF       clientPageSize = (e.BrickGraphics as BrickGraphics).ClientPageSize;


                    //Draw other cells
                    TextBrick tb = new TextBrick();
                    tb.Style.Padding = new PaddingInfo(2, 0, 0, 0);
                    tb.BackColor     = gridView.Appearance.Row.BackColor;
                    tb.Text          = (string)dataRow["Name1"];
                    tb.HorzAlignment = HorzAlignment.Near;
                    float        textBrickHeight = vi.ColumnRowHeight;
                    GridCellInfo info            = vi.GetGridCellInfo(e.RowHandle, gridView.Columns[0]);
                    RectangleF   textBrickRect   = new RectangleF(e.X, e.Y, printInfo.Columns[0].Bounds.Width, (int)textBrickHeight);
                    e.BrickGraphics.DrawBrick(tb, textBrickRect);

                    //Draw merged cells
                    TextBrick mergedTextBreak = new TextBrick();
                    mergedTextBreak.Style.Padding = new PaddingInfo(2, 0, 0, 0);
                    mergedTextBreak.BackColor     = gridView.Appearance.Row.BackColor;
                    mergedTextBreak.Text          = (string)dataRow["Name2"];
                    mergedTextBreak.HorzAlignment = HorzAlignment.Near;

                    GridCellInfo mergedInfo          = vi.GetGridCellInfo(e.RowHandle, gridView.Columns[1]);
                    RectangleF   textMergedBrickRect = new RectangleF(printInfo.Columns[1].Bounds.X, e.Y, ((PrintColumnInfo)printInfo.Columns[printInfo.Columns.Count - 1]).Bounds.Right - printInfo.Columns[0].Bounds.Width, (int)textBrickHeight);
                    e.BrickGraphics.DrawBrick(mergedTextBreak, textMergedBrickRect);


                    e.Y     += (int)textBrickHeight;
                    e.Cancel = true;
                }
            }
        }
Exemplo n.º 6
0
        private GridCellInfoCollection GetMergeCells(int rowHandle, GridColumn column)
        {
            GridViewInfo    viewInfo = gridView1.GetViewInfo() as GridViewInfo;
            GridDataRowInfo rowInfo  = viewInfo.GetGridRowInfo(rowHandle) as GridDataRowInfo;

            if (rowInfo != null)
            {
                GridCellInfo cellInfo = rowInfo.Cells[column];
                if (cellInfo != null && cellInfo.IsMerged)
                {
                    return(cellInfo.MergedCell.MergedCells);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public Cursor GetDragCursor(int rowHandle, Point e)
        {
            GridViewInfo info        = _View.GetViewInfo() as GridViewInfo;
            GridRowInfo  rowInfo     = info.GetGridRowInfo(rowHandle);
            Rectangle    imageBounds = new Rectangle(new Point(0, 0), rowInfo.TotalBounds.Size);
            Rectangle    totalBounds = new Rectangle(new Point(0, 0), info.Bounds.Size);
            Bitmap       bitmap      = new Bitmap(totalBounds.Width, totalBounds.Height);

            //Grid
            Bitmap    gridBitmap = new Bitmap(totalBounds.Width, totalBounds.Height);
            Rectangle rectBound  = _View.GridControl.Bounds;

            rectBound.X = 0;
            rectBound.Y = 0;
            _View.GridControl.DrawToBitmap(gridBitmap, rectBound);


            DevExpress.Utils.Drawing.GraphicsCache cache = new DevExpress.Utils.Drawing.GraphicsCache(Graphics.FromImage(bitmap));

            GridViewDrawArgs args = new GridViewDrawArgs(cache, info, totalBounds);

            DrawRow(args, rowInfo);

            Bitmap   result         = new Bitmap(imageBounds.Width, imageBounds.Height);
            Graphics resultGraphics = Graphics.FromImage(result);

            float[][] matrixItems =
            {
                new float[] { 1, 0, 0,    0, 0 },
                new float[] { 0, 1, 0,    0, 0 },
                new float[] { 0, 0, 1,    0, 0 },
                new float[] { 0, 0, 0, 0.7f, 0 },
                new float[] { 0, 0, 0,    0, 1 }
            };
            ColorMatrix     colorMatrix     = new ColorMatrix(matrixItems);
            ImageAttributes imageAttributes = new ImageAttributes();

            imageAttributes.SetColorMatrix(
                colorMatrix,
                ColorMatrixFlag.Default,
                ColorAdjustType.Bitmap);
            resultGraphics.DrawImage(gridBitmap, imageBounds, rowInfo.TotalBounds.X, rowInfo.TotalBounds.Y, rowInfo.TotalBounds.Width, rowInfo.TotalBounds.Height, GraphicsUnit.Pixel, imageAttributes);
            Point offset = new Point(e.X - rowInfo.TotalBounds.X, e.Y - rowInfo.TotalBounds.Y);

            //result.Save("file" + DateTime.Now.Millisecond + ".bmp");

            return(CreateCursor(result, offset));
        }
Exemplo n.º 8
0
        private void bidGridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            if (e.Column == this.gcAmount2)
            {
                GridViewInfo   gvi = (GridViewInfo)this.bidGridView.GetViewInfo();
                GridRowInfo    gri = gvi.GetGridRowInfo(e.RowHandle);
                OrderBookEntry ee  = (OrderBookEntry)this.bidGridView.GetRow(e.RowHandle);
                if (ee == null)
                {
                    return;
                }

                int height = ScaleUtils.ScaleValue(3);
                int width  = (int)(gri.Bounds.Width * ee.VolumePercent + 0.5f);
                e.Cache.FillRectangle(Color.FromArgb(0x20, Exchange.BidColor), new Rectangle(gri.Bounds.Right - width, gri.Bounds.Y, width, gri.Bounds.Height));
            }
        }
        public Bitmap GetRowDragBitmap(int rowHandle)
        {
            Bitmap       bmpView     = null;
            Bitmap       bmpRow      = null;
            GridViewInfo info        = _view.GetViewInfo() as GridViewInfo;
            Rectangle    totalBounds = info.Bounds;
            GridRowInfo  ri          = info.GetGridRowInfo(rowHandle);
            Rectangle    imageBounds = new Rectangle(new Point(0, 0), ri.Bounds.Size);

            try
            {
                bmpView = new Bitmap(totalBounds.Width, totalBounds.Height);
                using (Graphics gView = Graphics.FromImage(bmpView))
                {
                    using (XtraBufferedGraphics grView = XtraBufferedGraphicsManager.Current.Allocate(gView, new Rectangle(Point.Empty, bmpView.Size)))
                    {
                        Color color = ri.Appearance.BackColor == Color.Transparent ? Color.White : ri.Appearance.BackColor;
                        grView.Graphics.Clear(color);
                        IntPtr           handle    = View.GridControl.Handle;
                        DXPaintEventArgs paintArgs = new DXPaintEventArgs(new PaintEventArgs(grView.Graphics, totalBounds), handle);
                        DevExpress.Utils.Drawing.GraphicsCache cache = new DevExpress.Utils.Drawing.GraphicsCache(paintArgs);
                        GridViewDrawArgs args = new GridViewDrawArgs(cache, info, totalBounds);
                        DrawRow(args, ri);
                        grView.Graphics.FillRectangle(args.Cache.GetSolidBrush(Color.Transparent), ri.Bounds);
                        grView.Render();
                        bmpRow = new Bitmap(ri.Bounds.Width, ri.Bounds.Height);
                        using (Graphics gRow = Graphics.FromImage(bmpRow))
                        {
                            using (XtraBufferedGraphics grRow = XtraBufferedGraphicsManager.Current.Allocate(gRow, new Rectangle(Point.Empty, bmpRow.Size)))
                            {
                                grRow.Graphics.Clear(color);
                                grRow.Graphics.DrawImage(bmpView, imageBounds, ri.Bounds, GraphicsUnit.Pixel);
                                grRow.Render();
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(bmpRow);
        }
        public Rectangle GetAutoFilterRowBounds()
        {
            GridViewInfo    viewInfo = _View.GetViewInfo() as GridViewInfo;
            GridDataRowInfo rowInfo  = viewInfo.GetGridRowInfo(GridControl.AutoFilterRowHandle) as GridDataRowInfo;

            if (rowInfo == null || (rowInfo.RowState & GridRowCellState.Focused) != 0)
            {
                return(Rectangle.Empty);
            }
            Rectangle r = rowInfo.DataBounds;

            if (r.X < viewInfo.ViewRects.ColumnPanelLeft)
            {
                r.X = viewInfo.ViewRects.ColumnPanelLeft;
            }
            if (r.Right > viewInfo.ViewRects.Rows.Right)
            {
                r.Width = viewInfo.ViewRects.Rows.Right - r.X;
            }
            return(r);
        }
Exemplo n.º 11
0
        public Cursor GetDragRowCursor(int rowHandle, Point e)
        {
            GridViewInfo info    = _View.GetViewInfo() as GridViewInfo;
            GridRowInfo  rowInfo = info.GetGridRowInfo(rowHandle);

            if (rowInfo == null)
            {
                return(Cursor.Current);
            }
            Rectangle imageBounds = new Rectangle(new Point(0, 0), rowInfo.TotalBounds.Size);
            Rectangle totalBounds = new Rectangle(new Point(0, 0), info.Bounds.Size);
            Bitmap    bitmap      = new Bitmap(totalBounds.Width, totalBounds.Height);

            DevExpress.Utils.Drawing.GraphicsCache cache = new DevExpress.Utils.Drawing.GraphicsCache(Graphics.FromImage(bitmap));
            GridViewDrawArgs args = new GridViewDrawArgs(cache, info, totalBounds);

            DrawRow(args, rowInfo);
            Bitmap   result         = new Bitmap(imageBounds.Width, imageBounds.Height);
            Graphics resultGraphics = Graphics.FromImage(result);

            float[][] matrixItems =
            {
                new float[] { 1, 0, 0,    0, 0 },
                new float[] { 0, 1, 0,    0, 0 },
                new float[] { 0, 0, 1,    0, 0 },
                new float[] { 0, 0, 0, 0.7f, 0 },
                new float[] { 0, 0, 0,    0, 1 }
            };
            ColorMatrix     colorMatrix     = new ColorMatrix(matrixItems);
            ImageAttributes imageAttributes = new ImageAttributes();

            imageAttributes.SetColorMatrix(
                colorMatrix,
                ColorMatrixFlag.Default,
                ColorAdjustType.Bitmap);
            resultGraphics.DrawImage(bitmap, imageBounds, rowInfo.TotalBounds.X, rowInfo.TotalBounds.Y, rowInfo.TotalBounds.Width, rowInfo.TotalBounds.Height, GraphicsUnit.Pixel, imageAttributes);
            resultGraphics.DrawIcon(Icon.FromHandle(Cursors.Default.Handle), 0, 0);
            return(CreateCursor(result));
        }
Exemplo n.º 12
0
        void GridControl_Paint(object sender, PaintEventArgs e)
        {
            if (_downHitInfo == null)
            {
                return;
            }
            GridControl grid = (GridControl)sender;
            GridView    view = (GridView)grid.MainView;

            bool isBottomLine = DropTargetRowHandle == view.DataRowCount;

            GridViewInfo viewInfo = view.GetViewInfo() as GridViewInfo;
            GridRowInfo  rowInfo  = viewInfo.GetGridRowInfo(isBottomLine ? DropTargetRowHandle - 1 : DropTargetRowHandle);

            if (rowInfo == null)
            {
                return;
            }

            Point p1, p2;

            if (isBottomLine)
            {
                p1 = new Point(rowInfo.Bounds.Left, rowInfo.Bounds.Bottom - 1);
                p2 = new Point(rowInfo.Bounds.Right, rowInfo.Bounds.Bottom - 1);
            }
            else
            {
                p1 = new Point(rowInfo.Bounds.Left, rowInfo.Bounds.Top - 1);
                p2 = new Point(rowInfo.Bounds.Right, rowInfo.Bounds.Top - 1);
            }

            Pen pen = new Pen(ColorTranslator.FromHtml("#2091E1"), 3);

            e.Graphics.DrawLine(pen, p1, p2);
        }
Exemplo n.º 13
0
        public Cursor GetDragRowsCursor(int[] rowHandles, Point poi)
        {
            if (rowHandles == null || rowHandles.Length == 0)
            {
                return(Cursor.Current);
            }

            //return DevExpress.Utils.DragAndDropCursors.MoveEffectCursor;

            GridViewInfo vi = _View.GetViewInfo() as GridViewInfo;

            //需要绘制的第一行(选中并且grid中显示的)
            var topRowInfo = vi.GetGridRowInfo(new[] { rowHandles.Min(), _View.TopRowIndex }.Max());

            //需要绘制的最后一行 (选中并且grid中显示的)
            var btmRowInfo = vi.GetGridRowInfo(new[] { rowHandles.Max(), vi.RowsInfo.Max(x => x.VisibleIndex) }.Min());

            //没有显示选中行
            if (topRowInfo == null || btmRowInfo == null)
            {
                return(Cursor.Current);
            }


            //所有选中行的高度和
            var height = Rectangle.Union(topRowInfo.Bounds, btmRowInfo.Bounds).Size.Height;

            //所有列的宽度和
            var width = vi.ColumnsInfo.Where(x => x.Type == GridColumnInfoType.Indicator || x.Type == GridColumnInfoType.Column).Sum(x => x.Bounds.Width);

            //最终图像的矩形
            var imageBounds = new Rectangle(new Point(0, 0), new Size(width, height));

            //绘制
            var imgTmp = new Bitmap(imageBounds.Width, imageBounds.Height);

            using (var gTmp = Graphics.FromImage(imgTmp))
            {
                //draw control to bitmap
                var ctrl       = _View.GridControl;
                var imgControl = new Bitmap(ctrl.Width, ctrl.Height);
                ctrl.DrawToBitmap(imgControl, new Rectangle(0, 0, imgControl.Width, imgControl.Height));

                //从整个grid图像中截取需要的图像
                gTmp.DrawImage(imgControl,
                               new Rectangle(0, 0, imgTmp.Width, imgTmp.Height),
                               new Rectangle(topRowInfo.Bounds.X, topRowInfo.Bounds.Y, imgTmp.Width, imgTmp.Height),
                               GraphicsUnit.Pixel);
            }

            //1/3比例缩放图片
            var img = new Bitmap(imgTmp, new Size(imgTmp.Width / 3, (imgTmp.Height / 3)));

            var imgCur = Icon.FromHandle(DevExpress.Utils.DragCursors.HandDragCursor.Handle);


            //最终返回的图像
            var imgRes = new Bitmap(img.Width + imgCur.Width, img.Height + imgCur.Height);

            using (var gRes = Graphics.FromImage(imgRes))
            {
                //将之前处理完成的图像绘制到新的图片中
                gRes.DrawImage(img, new Rectangle(new Point(imgCur.Width, imgCur.Height), img.Size));

                //将鼠标指针绘制到左上角
                gRes.DrawIcon(imgCur, 0, 0);
            }

            //从bitmap创建cursor
            return(CreateCursor(imgRes, imgCur.Width / 2, imgCur.Height / 2));
        }