/// <summary>
/// 绘制网格
/// </summary>
private void renderGrid()
{
//全局变量存储最大最小值,作为绘制区域
Graphics g = this.panel1.CreateGraphics();
Color color = Color.DarkGray;
Pen p = new Pen(color, 1);
p.DashStyle = DashStyle.Dash;
for (int x = 0; x <= this.panel1.Width; x = x + 20)
{
PointF p1 = new PointF(x, 0);
PointF p2 = new PointF(x, Height);
g.DrawLine(p, p1, p2);
}
for (int y = 0; y <= panel1.Height; y = y + 20)
{
PointF p1 = new PointF(0, y);
PointF p2 = new PointF(Width, y);
g.DrawLine(p, p1, p2);
}
}
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
int X = e.X;
int Y = e.Y;
if (this.__gObjType== "")
{
return;
}
if (this.__gObjType != "Line")
{
AddObjectFromMouseLocation(X, Y, 0, 0, this.__gObjType);
}
else
{
//line
if (__lineMouseClickedCount == 1)
{
__lineX2 = e.X;
__lineY2 = e.Y;
AddObjectFromMouseLocation(__lineX1, __lineY1, __lineX2, __lineY2, this.__gObjType);
//连接线方向判断
__lineMouseClickedCount = 0;
__lineX1 = 0;
__lineY1 = 0;
__lineX2 = 0;
__lineY2 = 0;
}
else if (__lineMouseClickedCount == 0)
{
__lineX1 = e.X;
__lineY1 = e.Y;
__lineMouseClickedCount = 1;
}
else
{
__lineMouseClickedCount = 0;
__lineX1 = 0;
__lineY1 = 0;
__lineX2 = 0;
__lineY2 = 0;
}
}
}
private void ReDrawAll()
{
renderGrid();
Graphics g = this.panel1.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
GObject CurrObj = new GObject();
Rectangle Rct = new Rectangle();
Pen p = new Pen(Color.Black);
//p.Width = 2;
p.Width = __penWidth * __zoomTimes;
Image ObjImg;
int xm = 0;
int ym = 0;
int _maxX = 0;
int _maxY = 0;
int _minX = 0;
int _minY = 0;
int _oldW = this.panel1.Width;
int _oldH = this.panel1.Height;
string IsLine = "";
//Nobj==50为当前画布最大的对象个数
for (int i = 0; i < GNetworkFlow.Nobj; i++)
{
CurrObj = GNetworkFlow.GObjects[i];
//当前对象类型判断
if (CurrObj.Type == "") IsLine = "N/D";
if (CurrObj.Type == "Line") IsLine = "Y";
if ((CurrObj.Type != "Line") && (CurrObj.Type != "")) IsLine = "N";
//
#region old panel1作为画布,将其嵌套在panel2中实现超出边界出现滚动条
if (_maxX < CurrObj.x2)
{
_maxX = CurrObj.x2;
}
if (_maxY < CurrObj.y2)
{
_maxY = CurrObj.y2;
}
if (_minX > CurrObj.x1)
{
_minX = CurrObj.x1;
}
if (_minY > CurrObj.y1)
{
_minY = CurrObj.y1;
}
if (_oldW < _maxX - _minX)
{
this.panel1.Width = _maxX - _minX;
}
if (_oldH < _maxY - _minY)
{
this.panel1.Height = _maxY - _minY;
}
if (this.panel1.Height < this.panel2.Height)
{
this.panel1.Height = this.panel2.Height;
}
if (this.panel1.Width < this.panel2.Width)
{
this.panel1.Width = this.panel2.Width;
}
#endregion
switch (IsLine)
{
case "Y":
arrow.DrawArrow(g, p, p.Brush, CurrObj.x1, CurrObj.y1, CurrObj.x2, CurrObj.y2);
xm = (CurrObj.x1 + CurrObj.x2) / 2;
ym = (CurrObj.y1 + CurrObj.y2) / 2;
AddText(xm, ym, CurrObj.Name, false);
break;
case "N":
Rct.X = CurrObj.x1;
Rct.Y = CurrObj.y1;
Rct.Width = CurrObj.x2 - CurrObj.x1;
Rct.Height = CurrObj.y2 - CurrObj.y1;
if (CurrObj.Type != String.Empty)
{
ObjImg = FindGObjectTypeImage(CurrObj.Type);
g.DrawImage(ObjImg, Rct);
AddText(CurrObj.x1, CurrObj.y1, CurrObj.Name, true);
GNetworkFlow.AdjustLinkedTo(CurrObj.Name);
}
break;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有