C#实现Dev Grid拖拽移动行的方法

拖拽时带行截图效果

C#实现Dev Grid拖拽移动行的方法

实现代码如下:

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

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

/// <summary>

/// 拖拽帮助类

/// </summary>

public static class DragHelper

{

  /// <summary>

  /// BandedGridView 拖拽

  /// </summary>

  /// <param name="gvMain"></param>

  public static void DragGridRow<T>(this BandedGridView gvMain)

  {

   // 拖拽遮罩控件

   DragMaster dragMaster = new DragMaster();

   // 当前拖拽行绘画区域

   Rectangle _DragRowRect = Rectangle.Empty;

   GridControl gcMain = gvMain.GridControl;

   GridHitInfo _DownHitInfo = null;

   //表格属性 允许拖拽

   gcMain.AllowDrop = true;

   gvMain.OptionsDetail.EnableMasterViewMode = false;

   #region 将对象拖至边界时发生 DragOver

   gcMain.DragOver += delegate(object sender, System.Windows.Forms.DragEventArgs e)

   {

    if (e.Data.GetDataPresent(typeof(T)))

     e.Effect = DragDropEffects.Move;

    else

     e.Effect = DragDropEffects.None;

   };

   #endregion

   #region 拖拽完成时处理数据 DragDrop

   gcMain.DragDrop += delegate(object sender, System.Windows.Forms.DragEventArgs e)

   {

    // 拖过来的新数据

    T newRow = (T)e.Data.GetData(typeof(T));

    // 原来在此坐标的数据

    // e的坐标是相对于屏幕的

    var clientPoint = gcMain.PointToClient(new Point(e.X, e.Y));

    GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(clientPoint.X, clientPoint.Y));

    var oldRow = (T)gvMain.GetRow(hitInfo.RowHandle);

    // 如果相等则不处理

    if (oldRow == null || newRow == null) return;

    // 且目标位置不是最后一行的话要将所有序号重排

    // 原来的行号

    var oldIndex = _DownHitInfo.RowHandle;

    // 新的行号

    var newIndex = hitInfo.RowHandle;

    BindingSource bs = (BindingSource)(gcMain.DataSource);

    if (bs == null)

     return;

    bs.RemoveAt(oldIndex);

    bs.Insert(oldIndex, oldRow);

    bs.RemoveAt(newIndex);

    bs.Insert(newIndex, newRow);

    bs.ResetBindings(false);

   };

   #endregion

   #region 鼠标按下 MouseDown

   gcMain.MouseDown += delegate(object sender, MouseEventArgs e)

   {

    _DownHitInfo = null;

    GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(e.X, e.Y));

    if (Control.ModifierKeys != Keys.None) return;

    if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)

    {

     // 禁用的Grid不支持拖拽

     if (!gvMain.OptionsBehavior.Editable

      || gvMain.OptionsBehavior.ReadOnly)

      return;

     // 只有点击最前面才能拖拽

     if (hitInfo.InRowCell)

      return;

     // 缓存

     _DownHitInfo = hitInfo;

    }

   };

   #endregion

   #region 鼠标移动 MouseMove

   gcMain.MouseMove += delegate(object sender, MouseEventArgs e)

   {

    if (e.Button == MouseButtons.Left)

    {

     if (_DownHitInfo != null)

     {

      Size dragSize = SystemInformation.DragSize;

      // 偏离区域

      Rectangle dragRect = new Rectangle(new Point(_DownHitInfo.HitPoint.X - dragSize.Width / 2, _DownHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);

      if (!dragRect.Contains(new Point(e.X, e.Y)))

      {

       // 屏幕坐标

       var p = gcMain.PointToScreen(e.Location);

       // 刷新是必须要的

       gcMain.Refresh();

       // 获取当前行截图

       var bmp = GetDragRowImage(gcMain, _DownHitInfo, _DragRowRect);

       Point offSetPoint = new Point(p.X + 1, p.Y - dragMaster.DragSize.Height / 2);

       // 开始显示拖拽遮罩

       dragMaster.StartDrag(bmp, offSetPoint, DragDropEffects.Move);

       // 获取要拖拽的数据

       object row = gvMain.GetRow(_DownHitInfo.RowHandle);

       // 开始拖拽

       gcMain.DoDragDrop(row, DragDropEffects.Move);

       // 取消事件

       DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;

       // 清空缓存

       _DownHitInfo = null;

      }

     }

    }

   };

   #endregion

   #region 在用鼠标拖动某项时发生,是否允许继续拖放 QueryContinueDrag

   gcMain.QueryContinueDrag += delegate(object sender, QueryContinueDragEventArgs e)

   {

    switch (e.Action)

    {

     case DragAction.Continue:

      // 移动遮罩

      Point offSetPoint = new Point(Cursor.Position.X + 1, Cursor.Position.Y - dragMaster.DragSize.Height / 2);

      dragMaster.DoDrag(offSetPoint, DragDropEffects.Move, false);

      break;

     default:

      // 清空

      _DragRowRect = Rectangle.Empty;

      // 停止拖动

      dragMaster.EndDrag();

      break;

    }

   };

   #endregion

   #region 点击行头移动行

   gvMain.CustomDrawRowIndicator += delegate(object sender, RowIndicatorCustomDrawEventArgs e)

   {

    if (_DragRowRect == Rectangle.Empty && _DownHitInfo != null && _DownHitInfo.RowHandle == e.RowHandle)

    {

     _DragRowRect = e.Bounds;

    }

   };

   #endregion

  }

  /// <summary>

  /// GridView 拖拽

  /// </summary>

  /// <param name="gvMain"></param>

  public static void DragGridRow<T>(this GridView gvMain)

  {

   // 拖拽遮罩控件

   DragMaster dragMaster = new DragMaster();

   // 当前拖拽行绘画区域

   Rectangle _DragRowRect = Rectangle.Empty;

   GridControl gcMain = gvMain.GridControl;

   GridHitInfo _DownHitInfo = null;

   //表格属性 允许拖拽

   gcMain.AllowDrop = true;

   gvMain.OptionsDetail.EnableMasterViewMode = false;

   #region 将对象拖至边界时发生 DragOver

   gcMain.DragOver += delegate(object sender, System.Windows.Forms.DragEventArgs e)

   {

    if (e.Data.GetDataPresent(typeof(T)))

     e.Effect = DragDropEffects.Move;

    else

     e.Effect = DragDropEffects.None;

   };

   #endregion

   #region 拖拽完成时处理数据 DragDrop

   gcMain.DragDrop += delegate(object sender, System.Windows.Forms.DragEventArgs e)

   {

    // 拖过来的新数据

    T newRow = (T)e.Data.GetData(typeof(T));

    // 原来在此坐标的数据

    // e的坐标是相对于屏幕的

    var clientPoint = gcMain.PointToClient(new Point(e.X, e.Y));

    GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(clientPoint.X, clientPoint.Y));

    var oldRow = (T)gvMain.GetRow(hitInfo.RowHandle);

    // 如果相等则不处理

    if (oldRow == null || newRow == null) return;

    // 且目标位置不是最后一行的话要将所有序号重排

    // 原来的行号

    var oldIndex = _DownHitInfo.RowHandle;

    // 新的行号

    var newIndex = hitInfo.RowHandle;

      BindingSource bs = (BindingSource)(gcMain.DataSource);

    if (bs == null)

     return;

      bs.RemoveAt(oldIndex);

    bs.Insert(oldIndex, oldRow);

    bs.RemoveAt(newIndex);

    bs.Insert(newIndex, newRow);

    bs.ResetBindings(false);

   };

   #endregion

   #region 鼠标按下 MouseDown

   gcMain.MouseDown += delegate(object sender, MouseEventArgs e)

   {

    _DownHitInfo = null;

    GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(e.X, e.Y));

    if (Control.ModifierKeys != Keys.None) return;

    if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)

    {

     // 禁用的Grid不支持拖拽

     if (!gvMain.OptionsBehavior.Editable

      || gvMain.OptionsBehavior.ReadOnly)

      return;

     // 只有点击最前面才能拖拽

     if (hitInfo.InRowCell)

      return;

     // 缓存

     _DownHitInfo = hitInfo;

    }

   };

   #endregion

   #region 鼠标移动 MouseMove

   gcMain.MouseMove += delegate(object sender, MouseEventArgs e)

   {

    if (e.Button == MouseButtons.Left)

    {

     if (_DownHitInfo != null)

     {

      Size dragSize = SystemInformation.DragSize;

      // 偏离区域

      Rectangle dragRect = new Rectangle(new Point(_DownHitInfo.HitPoint.X - dragSize.Width / 2, _DownHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);

        if (!dragRect.Contains(new Point(e.X, e.Y)))

      {

       // 屏幕坐标

       var p = gcMain.PointToScreen(e.Location);

       // 刷新是必须要的

       gcMain.Refresh();

       // 获取当前行截图

       var bmp = GetDragRowImage(gcMain, _DownHitInfo, _DragRowRect);

       Point offSetPoint = new Point(p.X + 1, p.Y - dragMaster.DragSize.Height / 2);

       // 开始显示拖拽遮罩

       dragMaster.StartDrag(bmp, offSetPoint, DragDropEffects.Move);

       // 获取要拖拽的数据

       object row = gvMain.GetRow(_DownHitInfo.RowHandle);

       // 开始拖拽

       gcMain.DoDragDrop(row, DragDropEffects.Move);

       // 取消事件

       DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;

       // 清空缓存

       _DownHitInfo = null;

      }

     }

    }

   };

   #endregion

   #region 在用鼠标拖动某项时发生,是否允许继续拖放 QueryContinueDrag

   gcMain.QueryContinueDrag += delegate(object sender, QueryContinueDragEventArgs e)

   {

    switch (e.Action)

    {

     case DragAction.Continue:

      // 移动遮罩

      Point offSetPoint = new Point(Cursor.Position.X + 1, Cursor.Position.Y - dragMaster.DragSize.Height / 2);

      dragMaster.DoDrag(offSetPoint, DragDropEffects.Move, false);

      break;

     default:

      // 清空

      _DragRowRect = Rectangle.Empty;

      // 停止拖动

      dragMaster.EndDrag();

      break;

    }

   };

   #endregion

   #region 点击行头移动行

   gvMain.CustomDrawRowIndicator += delegate(object sender, RowIndicatorCustomDrawEventArgs e)

   {

    if (_DragRowRect == Rectangle.Empty && _DownHitInfo != null && _DownHitInfo.RowHandle == e.RowHandle)

    {

     _DragRowRect = e.Bounds;

    }

   };

   #endregion

   }

  /// <summary>

  /// 获取拖拽截图

  /// </summary>

  /// <param name="hitInfo"></param>

  /// <param name="gcMain"></param>

  /// <param name="dragRowRect"></param>

  /// <returns></returns>

  private static Bitmap GetDragRowImage(GridControl gcMain, GridHitInfo hitInfo, Rectangle dragRowRect)

  {

   // 截图

   var bmp = DevImageCapturer.GetControlBitmap(gcMain, null

   , dragRowRect.Width + 1, dragRowRect.Top

   , gcMain.Width - dragRowRect.Width - 4, dragRowRect.Height - 1);

     using (Graphics g = Graphics.FromImage(bmp))

   {

    var p1 = new Point(1, 1);

    var p2 = new Point(bmp.Width - 1, 1);

    var p3 = new Point(1, bmp.Height - 2);

    var p4 = new Point(bmp.Width - 1, bmp.Height - 2);

    using (Pen pen = new Pen(gcMain.ForeColor))

    {

     g.DrawLine(pen, p1, p2);

     g.DrawLine(pen, p1, p3);

     g.DrawLine(pen, p2, p4);

     g.DrawLine(pen, p3, p4);

    }

   }

   return bmp;

  }

}

/// <summary>

/// 拖拽窗口

/// </summary>

public partial class DragWindow : DevExpress.Utils.Win.TopFormBase

{

  private Bitmap dragBitmap;

  private bool dragging;

  private Point hotSpot;

  public static readonly Point InvisiblePoint = new Point(-100000, -100000);

  public DragWindow()

  {

   hotSpot = Point.Empty;

   dragging = false;

   SetStyle(ControlStyles.Selectable, false);

   this.Size = Size.Empty;

   this.ShowInTaskbar = false;

   Form prevActive = Form.ActiveForm;

   InitializeComponent();

  }

  void ActivateForm(object sender, EventArgs e)

  {

   Form form = sender as Form;

   if (form == null || !form.IsHandleCreated) return;

   form.Activate();

  }

  public void MakeTopMost()

  {

   UpdateZOrder();

  }

  private void InitializeComponent()

  {

   this.StartPosition = FormStartPosition.Manual;

   dragBitmap = null;

   this.Enabled = false;

   this.MinimumSize = Size.Empty;

   this.Size = Size.Empty;

   this.Location = InvisiblePoint;

   this.Visible = false;

   this.TabStop = false;

   //this.Opacity = 0.7;// DevExpress.Utils.DragDrop.DragWindow.DefaultOpacity;

  }

  protected void InternalMoveBitmap(Point p)

  {

   //p.Offset(-hotSpot.X, -hotSpot.Y);

   this.SuspendLayout();

   this.Location = p;

   this.ResumeLayout();

  }

  protected override void OnResize(System.EventArgs e)

  {

   base.OnResize(e);

  }

  public bool ShowDrag(Point p)

  {

   if (this.BackgroundImage == null) return false;

   dragging = true;

   Visible = true;

   Refresh();

   InternalMoveBitmap(p);

   return true;

  }

  public bool MoveDrag(Point p)

  {

   if (!dragging) return false;

   InternalMoveBitmap(p);

   return true;

  }

  public bool HideDrag()

  {

   if (!dragging) return false;

   Visible = false;

   BackgroundImage = null;

   dragging = false;

   this.SuspendLayout();

   this.Size = Size.Empty;

   this.Location = InvisiblePoint;

   this.ResumeLayout();

   return true;

  }

  public Point HotSpot { get { return hotSpot; } set { hotSpot = value; } }

  public Bitmap DragBitmap

  {

   get { return dragBitmap; }

   set

   {

    this.BackgroundImage = value;

    if (value == null)

    {

     HideDrag();

    }

    else

     hotSpot = new Point(value.Size.Width / 2, value.Size.Height / 2);

    dragBitmap = value;

    Size = BackgroundImage.Size;

   }

  }

}

/// <summary>

/// 截图

/// </summary>

public class DevImageCapturer

{

  [System.Runtime.InteropServices.DllImport("USER32.dll")]

  internal static extern IntPtr GetDC(IntPtr dc);

  [System.Runtime.InteropServices.DllImport("USER32.dll")]

  internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

  [System.Runtime.InteropServices.DllImport("USER32.dll")]

  internal static extern IntPtr GetDesktopWindow();

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern IntPtr CreateCompatibleDC(IntPtr hdc);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern bool DeleteObject(IntPtr hObject);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern IntPtr CreateSolidBrush(int color);

  [System.Runtime.InteropServices.DllImport("gdi32.dll")]

  internal static extern IntPtr CreatePatternBrush(IntPtr hBitmap);

  /// <summary>

  /// 获取控件的截图

  /// </summary>

  /// <param name="control">控件</param>

  /// <param name="pattern">图片</param>

  /// <returns></returns>

  public static Bitmap GetControlBitmap(Control control, Bitmap pattern)

  {

   int width = control.Width;

   int height = control.Height;

   if (control is Form)

   {

    width = control.ClientRectangle.Width;

    height = control.ClientRectangle.Height;

   }

   IntPtr hdc = GetDC(control.Handle);

   IntPtr compDC = CreateCompatibleDC(hdc);

   IntPtr compHBmp = CreateCompatibleBitmap(hdc, width, height);

   IntPtr prev = SelectObject(compDC, compHBmp);

   IntPtr brush = IntPtr.Zero, prevBrush = IntPtr.Zero;

   if (pattern != null)

   {

    brush = CreatePatternBrush(pattern.GetHbitmap());

    prevBrush = SelectObject(compDC, brush);

   }

   Point pt = new Point(0, 0);

   BitBlt(compDC, 0, 0, width, height, hdc, pt.X, pt.Y, 0x00C000CA);

   SelectObject(compDC, prev);

   if (prevBrush != IntPtr.Zero)

    SelectObject(compDC, prevBrush);

   ReleaseDC(control.Handle, hdc);

   NativeMethods.DeleteDC(compDC);

   Bitmap bmp = Bitmap.FromHbitmap(compHBmp);

   DeleteObject(compHBmp);

   if (brush != IntPtr.Zero)

    DeleteObject(brush);

   return bmp;

  }

  /// <summary>

  /// 获取控件的截图

  /// </summary>

  /// <param name="control">控件</param>

  /// <param name="pattern">图片</param>

  /// <param name="offSetX">X</param>

  /// <param name="offSetY">Y</param>

  /// <param name="width">宽</param>

  /// <param name="height">高</param>

  /// <returns></returns>

  public static Bitmap GetControlBitmap(Control control, Bitmap pattern, int offSetX = 0, int offSetY = 0, int width = 0, int height = 0)

  {

   width = width == 0 ? control.Width : width;

   height = height == 0 ? control.Height : height;

   if (control is Form)

   {

    width = control.ClientRectangle.Width;

    height = control.ClientRectangle.Height;

   }

   IntPtr hdc = GetDC(control.Handle);

   IntPtr compDC = CreateCompatibleDC(hdc);

   IntPtr compHBmp = CreateCompatibleBitmap(hdc, width, height);

   IntPtr prev = SelectObject(compDC, compHBmp);

   IntPtr brush = IntPtr.Zero, prevBrush = IntPtr.Zero;

   if (pattern != null)

   {

    brush = CreatePatternBrush(pattern.GetHbitmap());

    prevBrush = SelectObject(compDC, brush);

   }

   Point pt = new Point(offSetX, offSetY);

   BitBlt(compDC, 0, 0, width, height, hdc, pt.X, pt.Y, 0x00C000CA);

   SelectObject(compDC, prev);

   if (prevBrush != IntPtr.Zero)

    SelectObject(compDC, prevBrush);

   ReleaseDC(control.Handle, hdc);

   NativeMethods.DeleteDC(compDC);

   Bitmap bmp = Bitmap.FromHbitmap(compHBmp);

   DeleteObject(compHBmp);

   if (brush != IntPtr.Zero)

    DeleteObject(brush);

   return bmp;

  }

}

 public class DragMaster

 {

  [ThreadStatic]

  static DragWindow dragWindow;

  bool dragInProgress;

  DragDropEffects effects;

  DragDropEffects lastEffect;

  static Cursor customizationCursor = null;

  double _opacity = 0.7;

    public double Opacity

  {

   get { return _opacity; }

   set { _opacity = value; }

  }

  public DragMaster()

  {

   dragInProgress = false;

   lastEffect = effects = DragDropEffects.None;

  }

    DragWindow DragWindow

  {

   get

   {

    if (dragWindow == null) dragWindow = new DragWindow() { Opacity = this.Opacity };

    return dragWindow;

   }

  }

  public DragDropEffects LastEffect

  {

   get { return lastEffect; }

  }

  public bool DragInProgress

  {

   get { return dragInProgress; }

  }

    /// <summary>

  /// 绘制大小

  /// </summary>

  public Size DragSize

  {

   get

   {

    if (DragWindow.DragBitmap == null) return Size.Empty;

    return DragWindow.DragBitmap.Size;

   }

  }

  /// <summary>

  /// 开始拖拽

  /// </summary>

  /// <param name="bmp"></param>

  /// <param name="startPoint"></param>

  /// <param name="effects"></param>

  public void StartDrag(Bitmap bmp, Point startPoint, DragDropEffects effects)

  {

   StopDrag();

   dragInProgress = true;

   this.effects = effects;

   lastEffect = effects;

   DragWindow.MakeTopMost();

   DragWindow.DragBitmap = bmp;

   DragWindow.ShowDrag(startPoint);

   SetDragCursor(effects);

  }

  /// <summary>

  /// 停止拖拽

  /// </summary>

  protected void StopDrag()

  {

   dragInProgress = false;

   lastEffect = effects = DragDropEffects.None;

   DragWindow.HideDrag();

  }

  /// <summary>

  /// 设置拖拽鼠标类型

  /// </summary>

  /// <param name="e"></param>

  public void SetDragCursor(DragDropEffects e)

  {

   if (e == DragDropEffects.None)

    Cursor.Current = CustomizationCursor;

   else

    Cursor.Current = Cursors.Default;

  }

  /// <summary>

  /// 拖拽

  /// </summary>

  /// <param name="p"></param>

  /// <param name="e"></param>

  /// <param name="setCursor"></param>

  public void DoDrag(Point p, DragDropEffects e, bool setCursor)

  {

   if (!dragInProgress) return;

   lastEffect = e;

   if (setCursor) SetDragCursor(e);

   DragWindow.MoveDrag(p);

  }

  /// <summary>

  /// 取消拖拽

  /// </summary>

  public void CancelDrag()

  {

   if (!dragInProgress) return;

   StopDrag();

  }

  /// <summary>

  /// 结束拖拽

  /// </summary>

  public void EndDrag()

  {

   if (!dragInProgress) return;

   StopDrag();

  }

  /// <summary>

  /// 自定义Cursor

  /// </summary>

  static Cursor CustomizationCursor

  {

   get

   {

    if (customizationCursor == null) customizationCursor = ResourceImageHelper.CreateCursorFromResources("DevExpress.XtraTreeList.Images.customization.cur", typeof(DragMaster).Assembly);

    return customizationCursor;

   }

  }

}