使用silverlight构建一个工作流设计器(十一)
2009-05-21 12:08:24 来源:WEB开发网转折点是动态增加到规则类中的,转折点向外暴露两个事件。
l 转折点拖拽移动事件:当转折点被鼠标拖拽移动时,需要重新设置规则的直线坐标点。
l 转折点双击事件:当双击转折点时,需要重新设定规则的直线坐标,自动对其线段。
转折点包含两个重要的属性:
l Radius:转折点图形的半径。
l CenterPosition:转折点的中心坐标(相对Canvas的坐标 )。
下面是转折点类的代码:
public partial class RuleTurnPoint : UserControl
{
public delegate void RuleTurnPointMoveDelegate(object sender, MouseEventArgs e, Point newPoint);
public delegate void DoubleClickDelegate(object sender, EventArgs e);
public event RuleTurnPointMoveDelegate RuleTurnPointMove;
public RuleTurnPoint()
{
InitializeComponent();
_doubleClickTimer = new System.Windows.Threading.DispatcherTimer();
_doubleClickTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
_doubleClickTimer.Tick += new EventHandler(_doubleClickTimer_Tick);
}
void _doubleClickTimer_Tick(object sender, EventArgs e)
{
_doubleClickTimer.Stop();
}
public Brush Fill
{
get
{
return eliTurnPoint.Fill;
}
set
{
eliTurnPoint.Fill = value;
}
}
public void ShowDisplayAutomation()
{
sbDisplay.Begin();
}
public void ShowCloseAutomation()
{
sbColse.Begin();
}
private void Canvas_MouseEnter(object sender, MouseEventArgs e)
{
}
Point mousePosition;
bool trackingMouseMove = false;
bool hadActualMove = false;
System.Windows.Threading.DispatcherTimer _doubleClickTimer;
public event DoubleClickDelegate OnDoubleClick;
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
if (_doubleClickTimer.IsEnabled)
{
_doubleClickTimer.Stop();
if (OnDoubleClick != null)
OnDoubleClick(this, e);
}
else
{
_doubleClickTimer.Start();
FrameworkElement element = sender as FrameworkElement;
mousePosition = e.GetPosition(null);
trackingMouseMove = true;
hadActualMove = false;
if (null != element)
{
element.CaptureMouse();
element.Cursor = Cursors.Hand;
}
}
}
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
FrameworkElement element = sender as FrameworkElement;
hadActualMove = false;
trackingMouseMove = false;
element.ReleaseMouseCapture();
mousePosition = e.GetPosition(null);
element.Cursor = null;
}
public double Radius
{
get
{
return eliTurnPoint.Width / 2;
}
}
public Point CenterPosition {
get
{
return new Point((double)this.GetValue(Canvas.LeftProperty) + Radius, (double)this.GetValue(Canvas.TopProperty) + Radius);
}
set
{
this.SetValue(Canvas.LeftProperty, value.X - Radius);
this.SetValue(Canvas.TopProperty, value.Y - Radius);
}
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (trackingMouseMove)
{
FrameworkElement element = sender as FrameworkElement;
element.Cursor = Cursors.Hand;
if (e.GetPosition(null) == mousePosition)
return;
hadActualMove = true;
double deltaV = e.GetPosition(null).Y - mousePosition.Y;
double deltaH = e.GetPosition(null).X - mousePosition.X;
double newTop = deltaV + CenterPosition.Y;
double newLeft = deltaH + CenterPosition.X;
Point p = new Point(newLeft, newTop);
CenterPosition = p;
if (RuleTurnPointMove != null)
{
RuleTurnPointMove(sender, e,p);
}
mousePosition = e.GetPosition(null);
}
}
}
Tags:使用 silverlight 构建
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接