DataBaseView.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using FastReport.Utils;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace FastReport.FastQueryBuilder
  6. {
  7. internal class DataBaseView : ListBox
  8. {
  9. private Rectangle dragBoxFromMouseDown;
  10. public Table SelectedTable => SelectedItem as Table;
  11. public DataBaseView()
  12. {
  13. DrawMode = DrawMode.OwnerDrawFixed;
  14. IntegralHeight = false;
  15. }
  16. public void FillTableList(List<Table> tl)
  17. {
  18. BeginUpdate();
  19. Items.Clear();
  20. foreach (Table tbl in tl)
  21. {
  22. Items.Add(tbl);
  23. }
  24. EndUpdate();
  25. }
  26. protected override void OnDrawItem(DrawItemEventArgs e)
  27. {
  28. e.DrawBackground();
  29. if (e.Index >= 0)
  30. {
  31. this.DrawImageAndText(e, this.GetImage(222), Items[e.Index].ToString());
  32. }
  33. }
  34. protected override void OnMouseDown(MouseEventArgs e)
  35. {
  36. base.OnMouseDown(e);
  37. if (SelectedItem != null)
  38. {
  39. Size dragSize = SystemInformation.DragSize;
  40. dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2),
  41. e.Y - (dragSize.Height / 2)), dragSize);
  42. }
  43. else
  44. dragBoxFromMouseDown = Rectangle.Empty;
  45. }
  46. protected override void OnMouseMove(MouseEventArgs e)
  47. {
  48. base.OnMouseMove(e);
  49. if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
  50. {
  51. if ((dragBoxFromMouseDown != Rectangle.Empty) &&
  52. !dragBoxFromMouseDown.Contains(e.X, e.Y))
  53. {
  54. DoDragDrop(SelectedItem, DragDropEffects.Copy);
  55. }
  56. }
  57. }
  58. protected override void OnMouseUp(MouseEventArgs e)
  59. {
  60. base.OnMouseUp(e);
  61. dragBoxFromMouseDown = Rectangle.Empty;
  62. }
  63. public void UpdateDpiDependencies()
  64. {
  65. ItemHeight = this.LogicalToDevice(18);
  66. }
  67. }
  68. }