UserControlBase.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace IMCS.Config
  8. {
  9. public class UserControlBase : UserControl
  10. {
  11. public short UserTag { get; set; }
  12. public DevExpress.XtraBars.PopupMenu popupMenu1;
  13. public delegate void Delegate_MouseDownTag(int value);
  14. public virtual event Delegate_MouseDownTag UserControlMouseDown;
  15. public delegate void Delegate_DragDropTag(int value);
  16. public virtual event Delegate_DragDropTag UserControlDragDropTag;
  17. public UserControlBase()
  18. {
  19. this.Load += (s, e) => { AllowDrop = true;
  20. };
  21. //this.MouseDown += (s, e) =>
  22. //{
  23. // UserControlBase userControl = s as UserControlBase;
  24. // if ((e.Button == System.Windows.Forms.MouseButtons.Left))
  25. // {
  26. // userControl.DoDragDrop(userControl, DragDropEffects.Copy | DragDropEffects.Move);
  27. // System.Console.WriteLine($"UserControlBase;=>{userControl.UserTag}");
  28. // //形成拖拽效果,移动+拷贝的组合效果
  29. // }
  30. //};
  31. //this.DragEnter += (s, e) =>
  32. //{
  33. // System.Console.WriteLine($"DragEnter--->UserControlBase--->>{UserTag}");
  34. // e.Effect = DragDropEffects.Copy;
  35. //};
  36. //this.DragDrop += (s, e) =>
  37. //{
  38. // System.Console.WriteLine($"DragDrop--->UserControlBase--->>{UserTag}");
  39. //};
  40. }
  41. public virtual void EventMoudeDown(int value)
  42. {
  43. if (UserControlMouseDown != null)
  44. {
  45. UserControlMouseDown(value);
  46. }
  47. }
  48. public virtual void EventMoudeDrag(int value)
  49. {
  50. if (UserControlDragDropTag != null)
  51. {
  52. UserControlDragDropTag(value);
  53. }
  54. }
  55. }
  56. public class LabelBase : Label
  57. {
  58. public short UserTag { get; set; }
  59. public LabelBase()
  60. {
  61. this.AllowDrop = true;
  62. this.MouseDown += (s, e) =>
  63. {
  64. LabelBase userControl = s as LabelBase;
  65. if ((e.Button == System.Windows.Forms.MouseButtons.Left))
  66. {
  67. userControl.DoDragDrop(userControl, DragDropEffects.Copy | DragDropEffects.Move);
  68. System.Console.WriteLine($"LabelBase;=>{userControl.Tag}");
  69. //形成拖拽效果,移动+拷贝的组合效果
  70. }
  71. };
  72. this.DragEnter += (s, e) =>
  73. {
  74. System.Console.WriteLine($"DragEnter--->LabelBase--->>{UserTag}");
  75. e.Effect = DragDropEffects.Copy;
  76. };
  77. //this.DragDrop += (s, e) =>
  78. //{
  79. // System.Console.WriteLine($"DragDrop--->LabelBase--->>{UserTag}");
  80. //};
  81. }
  82. }
  83. public class PanelBase : Panel
  84. {
  85. public short UserTag { get; set; }
  86. public PanelBase()
  87. {
  88. this.AllowDrop = true;
  89. this.MouseDown += (s, e) =>
  90. {
  91. PanelBase userControl = s as PanelBase;
  92. if ((e.Button == System.Windows.Forms.MouseButtons.Left))
  93. {
  94. userControl.DoDragDrop(userControl, DragDropEffects.Copy | DragDropEffects.Move);
  95. System.Console.WriteLine($"PanelBase;=>{userControl.Tag}");
  96. //形成拖拽效果,移动+拷贝的组合效果
  97. }
  98. };
  99. this.DragEnter += (s, e) =>
  100. {
  101. System.Console.WriteLine($"DragEnter--->PanelBase--->>{UserTag}");
  102. e.Effect = DragDropEffects.Copy;
  103. };
  104. //this.DragDrop += (s, e) =>
  105. //{
  106. // System.Console.WriteLine($"DragDrop--->PanelBase--->>{UserTag}");
  107. //};
  108. }
  109. }
  110. }