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;
///
/// 记录x坐标
///
Point _movePos;
bool _bMoveFlag = false;
#endregion
#region 属性
///
/// 名字
///
public string NodeName
{
get { return this.label.Text; }
set { this.label.Text = value; }
}
//2017-5-8
///
/// 节点描述
///
public string NodeNote
{
get { return this.lblNote.Text; }
set
{ this.lblNote.Text = value; }
}
//2017-5-11
///
/// 节点ID
///
public string NodeID
{
get { return this.lblID.Text; }
set
{ this.lblID.Text = value; }
}
///
/// 文本放置方式
///
public ContentAlignment TextAlign
{
get { return _textAlign; }
set { _textAlign = value; }
}
///
/// 图像
///
public System.Drawing.Image Image
{
get { return _image; }
set
{
_image = value;
if(!_bSelected)
this.BackgroundImage = _image;
}
}
///
/// 被选中图像
///
public System.Drawing.Image SelectdImage
{
get { return _selectedImage; }
set
{
_selectedImage = value;
if (_bSelected)
this.BackgroundImage = _selectedImage;
}
}
///
/// 中心点坐标
///
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));
}
}
///
/// 顶点
///
public Point TopPoint
{
get
{
return new Point(CenterPoint.X, CenterPoint.Y - (Size.Height / 2));
}
}
///
/// 底点
///
public Point BottomPoint
{
get
{
return new Point(CenterPoint.X, CenterPoint.Y + (Size.Height / 2));
}
}
///
/// 左点
///
public Point LeftPoint
{
get
{
return new Point(CenterPoint.X - (Size.Width / 2), CenterPoint.Y);
}
}
///
/// 右点
///
public Point RightPoint
{
get
{
return new Point(CenterPoint.X + (Size.Width / 2), CenterPoint.Y);
}
}
///
/// 控件是否在移动中
///
public bool BeMoveing
{
get { return _bMoveFlag; }
set { _bMoveFlag = value; }
}
///
/// 移动的偏移量
///
public Point MovePos
{
get { return _movePos; }
set { _movePos = value; }
}
///
/// 是否被选中
///
public bool BeSelected
{
get { return _bSelected; }
set
{
if (_bSelected != value)
{
_bSelected = value;
if (_bSelected)
BackgroundImage = _selectedImage;
else
BackgroundImage = _image;
}
}
}
///
/// 与该控件绑定的流程节点
///
public FlowNode FlowNode
{
get { return _flowNode; }
//set
//{ this.lblID.Text = value.ID; }
}
#endregion
#region 公开方法
///
/// 构造方法
///
public FlowNodeControl()
{
_flowNode = null;
_textAlign = ContentAlignment.BottomCenter;
InitializeComponent();
BackgroundImageLayout = ImageLayout.None;//.Stretch2017-5-11
BackgroundImage = _image;
}
///
/// 构造方法
///
/// 关联的节点
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
}
}