| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace HySoft.FlowEditor
- {
- public partial class FlowNodeControl : UserControl
- {
- #region 字段
- GraphicsPath _graphicsPath;
- ContentAlignment _textAlign;
- FlowNode _flowNode;
- bool _bSelected;
- Image _image;
- Image _selectedImage;
- /// <summary>
- /// 记录x坐标
- /// </summary>
- Point _movePos;
- bool _bMoveFlag = false;
- #endregion
- #region 属性
- /// <summary>
- /// 名字
- /// </summary>
- public string NodeName
- {
- get { return this.label.Text; }
- set { this.label.Text = value; }
- }
- //2017-5-8
- /// <summary>
- /// 节点描述
- /// </summary>
- public string NodeNote
- {
- get { return this.lblNote.Text; }
- set
- { this.lblNote.Text = value; }
- }
- //2017-5-11
- /// <summary>
- /// 节点ID
- /// </summary>
- public string NodeID
- {
- get { return this.lblID.Text; }
- set
- { this.lblID.Text = value; }
- }
- /// <summary>
- /// 文本放置方式
- /// </summary>
- public ContentAlignment TextAlign
- {
- get { return _textAlign; }
- set { _textAlign = value; }
- }
- /// <summary>
- /// 图像
- /// </summary>
- public System.Drawing.Image Image
- {
- get { return _image; }
- set
- {
- _image = value;
- if(!_bSelected)
- this.BackgroundImage = _image;
- }
- }
- /// <summary>
- /// 被选中图像
- /// </summary>
- public System.Drawing.Image SelectdImage
- {
- get { return _selectedImage; }
- set
- {
- _selectedImage = value;
- if (_bSelected)
- this.BackgroundImage = _selectedImage;
- }
- }
- /// <summary>
- /// 中心点坐标
- /// </summary>
- public Point CenterPoint
- {
- get { return new Point(Location.X + (Size.Width/2), Location.Y+(Size.Height/2)); }
- set
- {
- Location = new Point(value.X - (Size.Width / 2), value.Y - (Size.Height / 2));
- }
- }
- /// <summary>
- /// 顶点
- /// </summary>
- public Point TopPoint
- {
- get
- {
- return new Point(CenterPoint.X, CenterPoint.Y - (Size.Height / 2));
- }
- }
- /// <summary>
- /// 底点
- /// </summary>
- public Point BottomPoint
- {
- get
- {
- return new Point(CenterPoint.X, CenterPoint.Y + (Size.Height / 2));
- }
- }
- /// <summary>
- /// 左点
- /// </summary>
- public Point LeftPoint
- {
- get
- {
- return new Point(CenterPoint.X - (Size.Width / 2), CenterPoint.Y);
- }
- }
- /// <summary>
- /// 右点
- /// </summary>
- public Point RightPoint
- {
- get
- {
- return new Point(CenterPoint.X + (Size.Width / 2), CenterPoint.Y);
- }
- }
- /// <summary>
- /// 控件是否在移动中
- /// </summary>
- public bool BeMoveing
- {
- get { return _bMoveFlag; }
- set { _bMoveFlag = value; }
- }
- /// <summary>
- /// 移动的偏移量
- /// </summary>
- public Point MovePos
- {
- get { return _movePos; }
- set { _movePos = value; }
- }
- /// <summary>
- /// 是否被选中
- /// </summary>
- public bool BeSelected
- {
- get { return _bSelected; }
- set
- {
- if (_bSelected != value)
- {
- _bSelected = value;
- if (_bSelected)
- BackgroundImage = _selectedImage;
- else
- BackgroundImage = _image;
- }
- }
- }
- /// <summary>
- /// 与该控件绑定的流程节点
- /// </summary>
- public FlowNode FlowNode
- {
- get { return _flowNode; }
- //set
- //{ this.lblID.Text = value.ID; }
- }
- #endregion
- #region 公开方法
- /// <summary>
- /// 构造方法
- /// </summary>
- public FlowNodeControl()
- {
- _flowNode = null;
- _textAlign = ContentAlignment.BottomCenter;
- InitializeComponent();
- BackgroundImageLayout = ImageLayout.None;//.Stretch2017-5-11
- BackgroundImage = _image;
- }
- /// <summary>
- /// 构造方法
- /// </summary>
- /// <param name="flowNode">关联的节点</param>
- public FlowNodeControl(FlowNode flowNode)
- {
- _flowNode = flowNode;
- _textAlign = ContentAlignment.BottomCenter;
-
- InitializeComponent();
- //this.lblID.Text = flowNode.ID;
- BackgroundImageLayout = ImageLayout.None;//.Stretch2017-5-11
- BackgroundImage = _image;
- }
- #endregion
- #region 私有方法
- #endregion
- #region 控件响应事件
- private void pictureBox_MouseDown(object sender, MouseEventArgs e)
- {
- base.OnMouseDown(e);
- }
- private void pictureBox_MouseMove(object sender, MouseEventArgs e)
- {
- base.OnMouseMove(e);
- }
- private void pictureBox_MouseUp(object sender, MouseEventArgs e)
- {
- base.OnMouseUp(e);
- }
- private void label_MouseDown(object sender, MouseEventArgs e)
- {
- base.OnMouseDown(e);
- }
- private void label_MouseMove(object sender, MouseEventArgs e)
- {
- base.OnMouseMove(e);
- }
- private void label_MouseUp(object sender, MouseEventArgs e)
- {
- base.OnMouseUp(e);
- }
- private void FlowNodeControl_MouseDown(object sender, MouseEventArgs e)
- {
- //_bMoveFlag = true;//已经按下.
- //_xPos = e.X;//当前x坐标.
- //_yPos = e.Y;//当前y坐标.
- base.OnMouseDown(e);
- }
- private void FlowNodeControl_MouseMove(object sender, MouseEventArgs e)
- {
- if (_bMoveFlag)
- {
- //this.Left += Convert.ToInt16(e.X - _xPos);//设置x坐标.
- //this.Top += Convert.ToInt16(e.Y - _yPos);//设置y坐标.
- }
- }
- private void FlowNodeControl_MouseUp(object sender, MouseEventArgs e)
- {
- _bMoveFlag = false;
- }
- #endregion
-
- }
- }
|