This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
DragGridImageHelper.cs
74 lines (70 loc) · 3.26 KB
/
DragGridImageHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Drawing;
using DevExpress.XtraGrid.Views.Grid.Drawing;
using DevExpress.Utils.Drawing;
namespace DragAndDropBetweenGridAndTreeList
{
public class DragGridImageHelper : GridPainter
{
private readonly DevExpress.XtraGrid.Views.Grid.GridView _view;
public DragGridImageHelper(DevExpress.XtraGrid.Views.Grid.GridView view)
: base(view)
{
_view = view;
}
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);
}
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;
}
}
}