/// <summary> /// 显示画面 /// </summary> /// <param name="style">false:显示:Line,false:显示:点</param> public void Paint_Function(Laser_Style laserstyle) { try { if (Var.Length < 6300) { return; } } catch (Exception) { //throw; return; } int[] data = new int[Var.Length]; float length; float theta; float[] lengthX = new float[6300]; float[] lengthY = new float[6300]; //定义窗体大小 int halfWidth = this.Width / 2; int halfHeight = this.Height / 2; Console.WriteLine("Paint窗口的X坐标:" + halfWidth); Console.WriteLine("Paint窗口的X坐标:" + halfHeight); Console.WriteLine("接收到的数据长度 :" + data.Length); Graphics g = CreateGraphics(); for (int i = 0; i < data.Length; i++) { data[i] = (int)(Var[i] * addsd); } for (int i = 0; i < 6300; i++) //800 813 { length = data[i]; theta = (float)(i * 4 / 70 + 90); //(float)((i / 3) - 45); lengthX[i] = length * (float)(Math.Cos(Math.PI * theta / 180)); lengthY[i] = length * (float)(Math.Sin(Math.PI * theta / 180)); } g.Clear(this.BackColor); //清除画面 Pen laser = new Pen(Color.Red, 1); switch (laserstyle) { case Laser_Style.Point: Point[] point = new Point[6300]; for (int i = 0; i < 6300; i++) //800 813 { point[i].X = (int)(halfWidth + lengthX[i]); point[i].Y = (int)(halfHeight - lengthY[i]); } g.DrawLines(laser, point); break; case Laser_Style.Line: for (int i = 0; i < 6300; i++) //800 813 //下面是划线,有延时 { g.DrawLine(laser, halfWidth, halfHeight, halfWidth + lengthX[i], halfHeight - lengthY[i]); } break; default: break; } }
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 :; }