ivr流程编辑器

FlowNodeControl.cs 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4. namespace HySoft.FlowEditor
  5. {
  6. public partial class FlowNodeControl : UserControl
  7. {
  8. #region 字段
  9. GraphicsPath _graphicsPath;
  10. ContentAlignment _textAlign;
  11. FlowNode _flowNode;
  12. bool _bSelected;
  13. Image _image;
  14. Image _selectedImage;
  15. /// <summary>
  16. /// 记录x坐标
  17. /// </summary>
  18. Point _movePos;
  19. bool _bMoveFlag = false;
  20. #endregion
  21. #region 属性
  22. /// <summary>
  23. /// 名字
  24. /// </summary>
  25. public string NodeName
  26. {
  27. get { return this.label.Text; }
  28. set { this.label.Text = value; }
  29. }
  30. //2017-5-8
  31. /// <summary>
  32. /// 节点描述
  33. /// </summary>
  34. public string NodeNote
  35. {
  36. get { return this.lblNote.Text; }
  37. set
  38. { this.lblNote.Text = value; }
  39. }
  40. //2017-5-11
  41. /// <summary>
  42. /// 节点ID
  43. /// </summary>
  44. public string NodeID
  45. {
  46. get { return this.lblID.Text; }
  47. set
  48. { this.lblID.Text = value; }
  49. }
  50. /// <summary>
  51. /// 文本放置方式
  52. /// </summary>
  53. public ContentAlignment TextAlign
  54. {
  55. get { return _textAlign; }
  56. set { _textAlign = value; }
  57. }
  58. /// <summary>
  59. /// 图像
  60. /// </summary>
  61. public System.Drawing.Image Image
  62. {
  63. get { return _image; }
  64. set
  65. {
  66. _image = value;
  67. if(!_bSelected)
  68. this.BackgroundImage = _image;
  69. }
  70. }
  71. /// <summary>
  72. /// 被选中图像
  73. /// </summary>
  74. public System.Drawing.Image SelectdImage
  75. {
  76. get { return _selectedImage; }
  77. set
  78. {
  79. _selectedImage = value;
  80. if (_bSelected)
  81. this.BackgroundImage = _selectedImage;
  82. }
  83. }
  84. /// <summary>
  85. /// 中心点坐标
  86. /// </summary>
  87. public Point CenterPoint
  88. {
  89. get { return new Point(Location.X + (Size.Width/2), Location.Y+(Size.Height/2)); }
  90. set
  91. {
  92. Location = new Point(value.X - (Size.Width / 2), value.Y - (Size.Height / 2));
  93. }
  94. }
  95. /// <summary>
  96. /// 顶点
  97. /// </summary>
  98. public Point TopPoint
  99. {
  100. get
  101. {
  102. return new Point(CenterPoint.X, CenterPoint.Y - (Size.Height / 2));
  103. }
  104. }
  105. /// <summary>
  106. /// 底点
  107. /// </summary>
  108. public Point BottomPoint
  109. {
  110. get
  111. {
  112. return new Point(CenterPoint.X, CenterPoint.Y + (Size.Height / 2));
  113. }
  114. }
  115. /// <summary>
  116. /// 左点
  117. /// </summary>
  118. public Point LeftPoint
  119. {
  120. get
  121. {
  122. return new Point(CenterPoint.X - (Size.Width / 2), CenterPoint.Y);
  123. }
  124. }
  125. /// <summary>
  126. /// 右点
  127. /// </summary>
  128. public Point RightPoint
  129. {
  130. get
  131. {
  132. return new Point(CenterPoint.X + (Size.Width / 2), CenterPoint.Y);
  133. }
  134. }
  135. /// <summary>
  136. /// 控件是否在移动中
  137. /// </summary>
  138. public bool BeMoveing
  139. {
  140. get { return _bMoveFlag; }
  141. set { _bMoveFlag = value; }
  142. }
  143. /// <summary>
  144. /// 移动的偏移量
  145. /// </summary>
  146. public Point MovePos
  147. {
  148. get { return _movePos; }
  149. set { _movePos = value; }
  150. }
  151. /// <summary>
  152. /// 是否被选中
  153. /// </summary>
  154. public bool BeSelected
  155. {
  156. get { return _bSelected; }
  157. set
  158. {
  159. if (_bSelected != value)
  160. {
  161. _bSelected = value;
  162. if (_bSelected)
  163. BackgroundImage = _selectedImage;
  164. else
  165. BackgroundImage = _image;
  166. }
  167. }
  168. }
  169. /// <summary>
  170. /// 与该控件绑定的流程节点
  171. /// </summary>
  172. public FlowNode FlowNode
  173. {
  174. get { return _flowNode; }
  175. //set
  176. //{ this.lblID.Text = value.ID; }
  177. }
  178. #endregion
  179. #region 公开方法
  180. /// <summary>
  181. /// 构造方法
  182. /// </summary>
  183. public FlowNodeControl()
  184. {
  185. _flowNode = null;
  186. _textAlign = ContentAlignment.BottomCenter;
  187. InitializeComponent();
  188. BackgroundImageLayout = ImageLayout.None;//.Stretch2017-5-11
  189. BackgroundImage = _image;
  190. }
  191. /// <summary>
  192. /// 构造方法
  193. /// </summary>
  194. /// <param name="flowNode">关联的节点</param>
  195. public FlowNodeControl(FlowNode flowNode)
  196. {
  197. _flowNode = flowNode;
  198. _textAlign = ContentAlignment.BottomCenter;
  199. InitializeComponent();
  200. //this.lblID.Text = flowNode.ID;
  201. BackgroundImageLayout = ImageLayout.None;//.Stretch2017-5-11
  202. BackgroundImage = _image;
  203. }
  204. #endregion
  205. #region 私有方法
  206. #endregion
  207. #region 控件响应事件
  208. private void pictureBox_MouseDown(object sender, MouseEventArgs e)
  209. {
  210. base.OnMouseDown(e);
  211. }
  212. private void pictureBox_MouseMove(object sender, MouseEventArgs e)
  213. {
  214. base.OnMouseMove(e);
  215. }
  216. private void pictureBox_MouseUp(object sender, MouseEventArgs e)
  217. {
  218. base.OnMouseUp(e);
  219. }
  220. private void label_MouseDown(object sender, MouseEventArgs e)
  221. {
  222. base.OnMouseDown(e);
  223. }
  224. private void label_MouseMove(object sender, MouseEventArgs e)
  225. {
  226. base.OnMouseMove(e);
  227. }
  228. private void label_MouseUp(object sender, MouseEventArgs e)
  229. {
  230. base.OnMouseUp(e);
  231. }
  232. private void FlowNodeControl_MouseDown(object sender, MouseEventArgs e)
  233. {
  234. //_bMoveFlag = true;//已经按下.
  235. //_xPos = e.X;//当前x坐标.
  236. //_yPos = e.Y;//当前y坐标.
  237. base.OnMouseDown(e);
  238. }
  239. private void FlowNodeControl_MouseMove(object sender, MouseEventArgs e)
  240. {
  241. if (_bMoveFlag)
  242. {
  243. //this.Left += Convert.ToInt16(e.X - _xPos);//设置x坐标.
  244. //this.Top += Convert.ToInt16(e.Y - _yPos);//设置y坐标.
  245. }
  246. }
  247. private void FlowNodeControl_MouseUp(object sender, MouseEventArgs e)
  248. {
  249. _bMoveFlag = false;
  250. }
  251. #endregion
  252. }
  253. }