📄 wftransition.cs
字号:
//长或宽的一半
int halfWfActivityWidthOrHeight = WfActivity.WidthAndHeight / 2;
// 垂直 x 或 y方向
// 特殊处理以防止除0
if (x == 0 || y == 0)
{
//如果x=0and y>0为90度y轴-长或宽的一半(确定画图标的位置) 如果x=0and y<0则为270度
if (x == 0)
{
if (y > 0)
{
angle = 90;
x1 = target.X;
y1 = target.Y - halfWfActivityWidthOrHeight;
}
else
{
angle = 270;
x1 = target.X;
y1 = target.Y + halfWfActivityWidthOrHeight;
}
}
//如果y=0and x>0为0度x轴-长或宽的一半(确定画图标的位置) 如果y=0and x<0则为180度
else if (y == 0)
{
if (x > 0)
{
angle = 0;
x1 = target.X - halfWfActivityWidthOrHeight;
y1 = target.Y;
}
else
{
angle = 180;
x1 = target.X + halfWfActivityWidthOrHeight;
y1 = target.Y;
}
}
}
else
{
//计算角度 并计算图片的坐标
double xDIVy = x / y;
double yDIVx = y / x;
double c = Math.Atan(xDIVy);
angle = -(c * 180 / Math.PI);
angle += 90;
double c1 = Math.Atan(yDIVx);
if (xDIVy == 1)
{
if (x > 0)
{
x1 = target.X - halfWfActivityWidthOrHeight;
y1 = target.Y - halfWfActivityWidthOrHeight;
}
else
{
angle += 180;
x1 = target.X + halfWfActivityWidthOrHeight;
y1 = target.Y + halfWfActivityWidthOrHeight;
}
}
else if (xDIVy == -1)
{
if (x > 0)
{
angle += 180;
x1 = target.X - halfWfActivityWidthOrHeight;
y1 = target.Y + halfWfActivityWidthOrHeight;
}
else
{
x1 = target.X + halfWfActivityWidthOrHeight;
y1 = target.Y - halfWfActivityWidthOrHeight;
}
}
else if (xDIVy < -1)
{
x1 = halfWfActivityWidthOrHeight;
y1 = (int)(x1 / Math.Tan(c));
if (x > 0)
{
angle += 180;
x1 = target.X - x1;
}
else
{
x1 = target.X + x1;
}
if (y > 0)
{
y1 = target.Y + y1;
}
else
{
y1 = target.Y - y1;
}
}
else if (xDIVy > 1)
{
x1 = halfWfActivityWidthOrHeight;
y1 = (int)(x1 / Math.Tan(c));
if (x > 0)
{
x1 = target.X - x1;
}
else
{
angle += 180;
x1 = target.X + x1;
}
if (y > 0)
{
y1 = target.Y - y1;
}
else
{
y1 = target.Y + y1;
}
}
else if (xDIVy > -1 && xDIVy < 0)
{
y1 = halfWfActivityWidthOrHeight;
x1 = (int)(y1 / Math.Tan(c1));
if (x > 0)
{
angle += 180;
x1 = target.X + x1;
}
else
{
x1 = target.X - x1;
}
if (y > 0)
{
y1 = target.Y - y1;
}
else
{
y1 = target.Y + y1;
}
}
else if (xDIVy < 1 && xDIVy > 0)
{
y1 = halfWfActivityWidthOrHeight;
x1 = (int)(y1 / Math.Tan(c1));
if (x > 0)
{
x1 = target.X - x1;
}
else
{
angle += 180;
x1 = target.X + x1;
}
if (y > 0)
{
y1 = target.Y - y1;
}
else
{
y1 = target.Y + y1;
}
}
}
ImageAttributes imAtt = new ImageAttributes();
//设置颜色键
imAtt.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255));
// 画箭头
Bitmap arrowBitmap = WorkflowDesigner.Properties.Resources.trans_arrow;
int imgWidth = arrowBitmap.Width;
int imgHeight = arrowBitmap.Height;
Rectangle rcDest = new Rectangle();
rcDest.X = -imgWidth / 2;
rcDest.Y = -imgHeight / 2;
rcDest.Width = imgWidth;
rcDest.Height = imgWidth;
GraphicsState gs = g.Save();
//平移(世界变换矩阵平移)
g.TranslateTransform(x1, y1);
//根据角度旋转(世界变换旋转)
g.RotateTransform((float)angle);
//绘制图片
g.DrawImage(arrowBitmap, rcDest,
0, 0,
imgWidth,
imgWidth,
GraphicsUnit.Pixel,
imAtt);
//释放
imAtt.Dispose();
arrowBitmap.Dispose();
//还原到原来的表示状态
g.Restore(gs);
// sm add
if ((this.Name != "") || (this.conditions.Count > 0))
{
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
format1.Alignment = StringAlignment.Center;
format1.LineAlignment = StringAlignment.Near;
Brush brushString = new SolidBrush(Color.Black);
Font font = new Font("新宋体", 9);
String Caption = this.Name;
if (this.conditions.Count > 0)
{
if (Caption != "")
{
Caption = Caption + "\r\n [" + this.conditions.Count.ToString() + "个判断条件]";
}
else
Caption =" [" + this.conditions.Count.ToString() + "个判断条件]";
}
g.DrawString(Caption, font, brushString, new PointF(_x, _y + 9), format1);
format1.Dispose();
font.Dispose();
brushString.Dispose();
}
}
/// <summary>
/// 移动
/// </summary>
/// <param name="offX">移动新位置与原坐标偏移值的x轴坐标</param>
/// <param name="offY">>移动新位置与原坐标偏移值的y轴坐标</param>
public override void Move(int offX, int offY)
{
//将中心点坐标加上偏移值,得到最新的流转中间调整点
_x += offX;
_y += offY;
//根据中心点坐标绘制调整节点矩形
_rect = new Rectangle(_x - 4, _y - 4, 8, 8);
}
/// <summary>
/// 打开属性对话框
/// </summary>
public override void OpenPropertyDialog()
{
TransitionInfoDlg dlg = new TransitionInfoDlg();
dlg.WfTransition = this;
//dlg.List = this.conditions;
dlg.ShowDialog();
dlg.Dispose();
}
/// <summary>
/// 图形矩阵
/// </summary>
/// <returns>返回一个图形矩阵</returns>
public override Rectangle GetRange()
{
return new Rectangle(0, 0, 0, 0);
}
#endregion
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -