📄 mainwindow.cs
字号:
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Transparent;
//
// MainWindow
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(744, 465);
this.Controls.Add(this.toolBar);
this.Controls.Add(this.btnPick);
this.Controls.Add(this.ColorBox);
this.Controls.Add(this.MoreColor);
this.Controls.Add(this.statusBar);
this.Controls.Add(this.grpTool);
this.Controls.Add(this.Drawing);
this.Menu = this.mainMenu;
this.Name = "MainWindow";
this.Text = "MyPGS";
this.grpTool.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.statusBarImageType)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPoint)).EndInit();
this.ColorBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 主函数,程序入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainWindow());
}
#region 申明
/// <summary>
/// 图形存储集合等。
/// </summary>
DShapeList drawingList = new DShapeList(); //图元
DShapeList drawingListUndo = new DShapeList(); //Undo保存
DShapeList tempPoint = new DShapeList(); //多边形、曲线临时顶点
DShapeList pointViewList = new DShapeList(); //图元顶点框
DShapeList notchangeList = new DShapeList(); //不移图元
DShapeList notchangeListUndo = new DShapeList();
NewForm newForm = new NewForm(); //字体、线宽窗口
CircleForm newCircle = new CircleForm(); //顶点圆窗口
ArrayList pointCollection = new ArrayList(); //多边形、曲线顶点集合
NewRegion regionCollection = new NewRegion(); //图元区域集合
NewRegion regionCollectionUndo = new NewRegion();
PointArrayCollection pointArray = new PointArrayCollection(); //图元顶点数组集合
PointArrayCollection pointArrayUndo = new PointArrayCollection();
Type drawImageType = new Type(); //图元形状
Type drawImageTypeUndo = new Type();
NewRegionArray regionArrayCollection = new NewRegionArray(); //图元顶点区域集合
NewRegionArray regionArrayCollectionUndo = new NewRegionArray();
GraphicsPath regionPath; //线、多边形区域路径
Point[] tempPointArray; //图元顶点临时保存
Region[] tempRegion; //图元顶点区域临时数组
Point[] tempMovePoint; //拾取起始点保存
int regionIndex = 0; //拾取集合索引
int pointIndex; //拾取顶点索引
int Distance; //圆半径(临时)
int diameter; //圆直径(临时)
bool picked = false; //拾取与否
bool changed = false; //图元变换
bool mouseMove = false; //拾取是否移动
bool eraser = false;
//零时变量,常量
private MousePoint newPoint;
private MousePoint tempChangePoint;
private ImageType newType;
private GraphicsPath mousePath;
private Region newRegion;
private int EraserSize;
private Image newImage;
private string fileName = "NewFile";
private Color newColor = Color.Black;
private float lineWidth = 1;
private ImageType tempType;
#endregion
#region 画图事件
/// <summary>
/// 画图事件
/// </summary>
private void Drawing_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics displayGraphics = e.Graphics;
switch(newType)
{
case ImageType.Point:
displayGraphics.DrawRectangle(new Pen(newColor,lineWidth),new Rectangle(newPoint.StartP, new Size(1, 1)));
break;
case ImageType.Line:
displayGraphics.DrawLine(new Pen(newColor,lineWidth),newPoint.StartP,newPoint.EndP);
break;
case ImageType.Circle:
displayGraphics.DrawLine(new Pen(newColor),newPoint.StartP,newPoint.EndP);
break;
case ImageType.FillCircle:
displayGraphics.DrawLine(new Pen(newColor),newPoint.StartP,newPoint.EndP);
break;
case ImageType.Rectangle:
displayGraphics.DrawRectangle(new Pen(newColor,lineWidth),newPoint.Rect);
break;
case ImageType.FillRectangle:
displayGraphics.FillRectangle(new SolidBrush(newColor),newPoint.Rect);
break;
case ImageType.Ellipse:
displayGraphics.DrawEllipse(new Pen(newColor,lineWidth),newPoint.Rect);
break;
case ImageType.FillEllipse:
displayGraphics.FillEllipse(new SolidBrush(newColor),newPoint.Rect);
break;
case ImageType.Path:
displayGraphics.DrawPath(new Pen(newColor,lineWidth), mousePath);
break;
case ImageType.Eraser:
displayGraphics.FillRegion(new SolidBrush(newColor), newRegion);
break;
case ImageType.Polygon:
tempPoint.DrawList(displayGraphics);
break;
case ImageType.Curve:
tempPoint.DrawList(displayGraphics);
break;
case ImageType.ClosedCurve:
tempPoint.DrawList(displayGraphics);
break;
case ImageType.Empty:
break;
case ImageType.Pick:
if(picked == true)
{
pointViewList.DrawList(displayGraphics);
if(changed == true&&drawImageType[regionIndex]!=(int)ImageType.Path)
{
if(drawImageType[regionIndex]==(int)ImageType.Rectangle)
{
displayGraphics.DrawRectangle(new Pen(newColor,lineWidth), tempChangePoint.Rect);
}
else if(drawImageType[regionIndex]==(int)ImageType.FillRectangle)
{
displayGraphics.FillRectangle(new SolidBrush(newColor), tempChangePoint.Rect);
}
else if(drawImageType[regionIndex]==(int)ImageType.Ellipse
||drawImageType[regionIndex]==(int)ImageType.FillEllipse)
{
displayGraphics.DrawRectangle(new Pen(Color.Black,1), tempChangePoint.Rect);
}
}
}
break;
}
drawingList.DrawList(displayGraphics);
if(eraser == true)
notchangeList.DrawList(displayGraphics);
//g.Dispose();
}
private void Point2Region(Point[] p)
{
Point[] point = new Point[p.Length];
int j = 0;
foreach(Point newp in p)
{
point[j++]=newp;
}
tempRegion = new Region[p.Length];
for(int i=0;i<p.Length;i++)
{
point[i].Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
Rectangle r = new Rectangle(point[i],new Size((int)(4*lineWidth),(int)(4*lineWidth)));
Region rr = new Region(r);
tempRegion[i] = rr;
}
}
private void RegionMove(int index, int x, int y)
{
for(int i=0;i<pointArray[index].Length;i++)
{
pointArray[index][i].X = tempMovePoint[i].X + x;
pointArray[index][i].Y = tempMovePoint[i].Y + y;
}
}
private void PointView(int index)
{
Point tempPoint2;
foreach(Point tempPoint in pointArray[index])
{
tempPoint2 = tempPoint;
tempPoint.Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
tempPoint2.Offset((int)(2*lineWidth),(int)(2*lineWidth));
pointViewList.Add(new DHollowRectangle(new Point[]{tempPoint,tempPoint2},Color.DarkRed,1));
tempPoint.Offset((int)(2*lineWidth),(int)(2*lineWidth));
}
}
private void PointChange(int index)
{
Point tempPoint2;
for(int i=0;i<pointArray[index].Length;i++)
{
tempPoint2 = pointArray[index][i];
pointArray[index][i].Offset(-(int)(2*lineWidth),-(int)(2*lineWidth));
tempPoint2.Offset((int)(2*lineWidth),(int)(2*lineWidth));
pointViewList[i].pointchange(new Point[]{pointArray[index][i],tempPoint2});
pointArray[index][i].Offset((int)(2*lineWidth),(int)(2*lineWidth));
}
}
private void RegionChange(int index)
{
ImageType tempType = (ImageType)drawImageType[index];
switch(tempType)
{
case ImageType.Point:
regionCollection[index] = new Region(new Rectangle(pointArray[index][0], new Size((int)lineWidth*4, (int)lineWidth*4)));
break;
case ImageType.Line:
if(Math.Abs((float)(pointArray[index][0].Y-pointArray[index][1].Y)/(float)(pointArray[index][0].X-pointArray[index][1].X))<=1)
{
regionPath = new GraphicsPath(new Point[]{
new Point(pointArray[index][0].X,pointArray[index][0].Y-10),
new Point(pointArray[index][1].X,pointArray[index][1].Y-10),
new Point(pointArray[index][1].X,pointArray[index][1].Y+10),
new Point(pointArray[index][0].X,pointArray[index][0].Y+10),
new Point(pointArray[index][0].X,pointArray[index][0].Y-10)
},new byte[]{
(byte)PathPointType.Start,
(byte)PathPointType.Line,
(byte)PathPointType.Line,
(byte)PathPointType.Line,
(byte)PathPointType.Line
});
}
else
{
regionPath = new GraphicsPath(new Point[]{
new Point(pointArray[index][0].X-10,pointArray[index][0].Y),
new Point(pointArray[index][0].X+10,pointArray[index][0].Y),
new Point(pointArray[index][1].X+10,pointArray[index][1].Y),
new Point(pointArray[index][1].X-10,pointArray[index][1].Y),
new Point(pointArray[index][0].X-10,pointArray[index][0].Y)
},new byte[]{
(byte)PathPointType.Start,
(byte)PathPointType.Line,
(byte)PathPointType.Line,
(byte)PathPointType.Line,
(byte)PathPointType.Line
});
}
regionPath.CloseFigure();
regionCollection[index] = new Region(regionPath);
break;
case ImageType.Circle:
case ImageType.FillCircle:
Distance = (int)Math.Sqrt (Math.Pow((pointArray[index][0].X-pointArray[index][1].X),2.0)+Math.Pow((pointArray[index][0].Y-pointArray[index][1].Y),2.0));
pointArray[index][0].Offset(-Distance,-Distance);
diameter = Distance*2;
regionCollection[index] = new Region(new Rectangle(pointArray[index][0], new Size(diameter, diameter)));
pointArray[index][0].Offset(Distance,Distance);
break;
case ImageType.Polygon:
case ImageType.Curve:
case ImageType.ClosedCurve:
byte[] tempByte = new byte[pointArray[index].Length];
for(int i=0;i<pointArray[index].Length;i++)
{
if(i==0)
tempByte[i] = (byte)PathPointType.Start;
else
tempByte[i] = (byte)PathPointType.Line;
}
regionPath = new GraphicsPath(pointArray[index], tempByte);
regionPath.CloseFigure();
regionCollection[index] = new Region(regionPath);
break;
case ImageType.Text:
break;
}
}
#endregion
#region 画图框按钮
/// <summary>
/// 图画图按钮框事件
/// </summary>
private void AddPoint_Click(object sender, System.EventArgs e)
{
this.statusBar.Panels[0].Text = "Point";
newType = ImageType.Point;
}
private void AddLine_Click(object sender, System.EventArgs e)
{
this.statusBar.Panels[0].Text = "Line";
newType = ImageType.Line;
}
private void AddCircle_Click(object sender, System.EventArgs e)
{
this.statusBar.Panels[0].Text = "Circle";
newType = ImageType.Circle;
}
private void AddFillCircle_Click(object sender, System.EventArgs e)
{
this.statusBar.Panels[0].Text = "FillCircle";
newType = ImageType.FillCircle;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -