//创建工具Size选项背景图 public void CreateToolSelectionBackGroundImage(ToolsType theType, PictureBox targetPictureBox, int iCount) { Bitmap new3DBitmap = new Bitmap(targetPictureBox.Size.Width, targetPictureBox.Size.Height); Graphics tempGraphics = Graphics.FromImage(new3DBitmap); switch (theType) { case ToolsType.橡皮: if (iCount == (int)Tools.m_ToolSize) { tempGraphics.FillRectangle(Brushes.White, new Rectangle(0, 0, new3DBitmap.Width, new3DBitmap.Height)); tempGraphics.DrawRectangle(new Pen(Color.FromArgb(51, 153, 255)), new Rectangle(0, 0, new3DBitmap.Width - 1, new3DBitmap.Height - 1)); tempGraphics.DrawRectangle(new Pen(Color.FromArgb(51, 153, 255)), new Rectangle(1, 1, new3DBitmap.Width - 3, new3DBitmap.Height - 3)); } break; case ToolsType.喷枪: new3DBitmap.Dispose(); if (iCount == (int)Tools.m_ToolSize) { switch (iCount) { case 0: new3DBitmap = ReverseColor(new Bitmap("min.bmp")); break; case 1: new3DBitmap = ReverseColor(new Bitmap("mid.bmp")); break; case 2: new3DBitmap = ReverseColor(new Bitmap("max.bmp")); break; } } else { switch (iCount) { case 0: new3DBitmap = new Bitmap("min.bmp"); break; case 1: new3DBitmap = new Bitmap("mid.bmp"); break; case 2: new3DBitmap = new Bitmap("max.bmp"); break; } } break; case ToolsType.直线: case ToolsType.曲线: if (iCount == (int)Tools.m_ToolSize) { tempGraphics.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), new Rectangle(0, 0, new3DBitmap.Width, new3DBitmap.Height)); tempGraphics.DrawLine(new Pen(Color.White, iCount + 1), new Point(2, targetPictureBox.Height / 2), new Point(targetPictureBox.Width - 2, targetPictureBox.Height / 2)); } else { tempGraphics.FillRectangle(new SolidBrush(panelToolSelection.BackColor), new Rectangle(0, 0, new3DBitmap.Width, new3DBitmap.Height)); tempGraphics.DrawLine(new Pen(Color.Black, iCount + 1), new Point(2, targetPictureBox.Height / 2), new Point(targetPictureBox.Width - 2, targetPictureBox.Height / 2)); } break; case ToolsType.放大镜: break; case ToolsType.刷子: break; case ToolsType.文字: case ToolsType.定: case ToolsType.裁剪: if (iCount != (int)Tools.m_ToolSize) { tempGraphics.FillRectangle(new SolidBrush(panelToolSelection.BackColor), 0, 0, new3DBitmap.Width, new3DBitmap.Height); switch (iCount) { case 0: tempGraphics.DrawImageUnscaled(TransparentColor(new Bitmap("Mode-a.bmp"), Color.FromArgb(128, 0, 0), panelToolSelection.BackColor), 0, 3); break; case 1: tempGraphics.DrawImageUnscaled(TransparentColor(new Bitmap("Mode-b.bmp"), Color.FromArgb(128, 0, 0), panelToolSelection.BackColor), 0, 3); break; } } else { tempGraphics.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), 0, 0, new3DBitmap.Width, new3DBitmap.Height); switch (iCount) { case 0: tempGraphics.DrawImageUnscaled(TransparentColor(new Bitmap("Mode-a.bmp"), Color.FromArgb(128, 0, 0), Color.FromArgb(51, 153, 255)), 0, 3); break; case 1: tempGraphics.DrawImageUnscaled(TransparentColor(new Bitmap("Mode-b.bmp"), Color.FromArgb(128, 0, 0), Color.FromArgb(51, 153, 255)), 0, 3); break; } } break; case ToolsType.矩形: case ToolsType.椭圆: case ToolsType.多边形: case ToolsType.圆角矩形: const int iWageDistance = 3; int RuleX = targetPictureBox.Width - iWageDistance * 2 - 1; int RuleY = targetPictureBox.Height - iWageDistance * 2 - 1; if (iCount == (int)Tools.m_ToolSize) { tempGraphics.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), new Rectangle(0, 0, new3DBitmap.Width, new3DBitmap.Height)); tempGraphics.DrawRectangle(Pens.White, iWageDistance, iWageDistance, RuleX, RuleY); } else { tempGraphics.FillRectangle(new SolidBrush(panelToolSelection.BackColor), new Rectangle(0, 0, new3DBitmap.Width, new3DBitmap.Height)); tempGraphics.DrawRectangle(Pens.Black, iWageDistance, iWageDistance, RuleX, RuleY); } switch (iCount) { case (int)ToolSize.Size_1: break; case (int)ToolSize.Size_2: tempGraphics.FillRectangle(Brushes.Gray, new Rectangle(iWageDistance + 1, iWageDistance + 1, RuleX - 1, RuleY - 1)); break; case (int)ToolSize.Size_3: tempGraphics.FillRectangle(Brushes.Gray, new Rectangle(iWageDistance, iWageDistance, RuleX + 1, RuleY + 1)); break; } break; } targetPictureBox.BackgroundImage = new3DBitmap; }
private void pictureBox_MouseMove(Object sender, MouseEventArgs e) { if (dragNdrop) { this.pictureBox.Cursor = Cursors.SizeAll; } else { this.pictureBox.Cursor = Cursors.Cross; } if (drawMouse == false) { goto jump;// k phải đang dí chuột thì nhảy tới jump } x1 = e.X; y1 = e.Y; //g.Clear(Color.White); drawing = new Bitmap(drawingList.ElementAt(drawingList.currentIndex)); //pictureBox.Image = drawingList.Last(); g = Graphics.FromImage(drawing); //chọn pen Pen pen = choosePen(e); if (currentFillItem != fillType.NoFill) //vẽ phía trong { Brush brush = chooseBrush(e); brushShape(brush, x, y, x1, y1); } //Vẽ đường ngoài switch (currentItem) { case item.Select: { if (dragNdrop) { Console.WriteLine("Selecting"); //this.pictureBox.Cursor = Cursors.SizeAll; //tạo nét đứt xung quanh //dashDraw(new Rectangle(selectedArea.X+ (x1 - x), selectedArea.Y + (y1 - y),selectedArea.Width-1,selectedArea.Height)); //xoá hình select trên hình hiện tại Bitmap nullImage = new Bitmap(selectImage); Graphics nullGraphics = Graphics.FromImage(nullImage); nullGraphics.Clear(Color.White); g.DrawImageUnscaled(nullImage, selectedArea.X, selectedArea.Y); //vẽ hình select lên vị trí mới g.DrawImageUnscaled(selectImage, selectedArea.X + (x1 - x), selectedArea.Y + (y1 - y)); //pictureBox.Image = drawing; } else { dashDraw(Rectangle1(x, y, x1, y1)); } break; } case item.Pen: { //Pen pen = pen_properties(currentColor, currentWidth); //g.DrawLine(p, x, y, x1, y1); //x = x1; y = y1; pointList.Add(new Point(x1, y1)); try { g.DrawLines(pen, pointList.ToArray()); //g.DrawCurve(pen, pointList.ToArray()); ////g.DrawBeziers(pen, pointList.ToArray()); } catch (Exception ex) { } break; } case item.Eraser: { SolidBrush brush = new SolidBrush(Color.White); rectangleList.Add(new Rectangle(new Point(x1, y1), new Size(currentWidth, currentWidth))); g.FillRectangles(brush, rectangleList.ToArray()); break; } case item.Line: { g.DrawLine(pen, new Point(x, y), new Point(x1, y1)); //pictureBox1.CreateGraphics().DrawImageUnscaled(drawing, 0, 0); break; } case item.Oval: { g.DrawEllipse(pen, x, y, x1 - x, y1 - y); break; } case item.Rectangle: { g.DrawRectangle(pen, Rectangle1(x, y, x1, y1)); break; } case item.TriCan: { Point[] pList = new Point[3]; pList[0] = new Point((x + x1) / 2, y); pList[1] = new Point(x, y1); pList[2] = new Point(x1, y1); g.DrawPolygon(pen, pList); break; } case item.TriVuong: { Point[] pList = new Point[3]; pList[0] = new Point(x, y); pList[1] = new Point(x, y1); pList[2] = new Point(x1, y1); g.DrawPolygon(pen, pList); break; } case item.Diamond: { Point[] pList = new Point[4]; pList[0] = new Point((x + x1) / 2, y); pList[1] = new Point(x, (y + y1) / 2); pList[2] = new Point((x + x1) / 2, y1); pList[3] = new Point(x1, (y + y1) / 2); g.DrawPolygon(pen, pList); break; } } pictureBox.Image = drawing; // hiển thị jump :; }