internal override void Draw(Graphics g, ImageBox box) { if (!Visible || this.IsEmpty()) { return; } var pt1 = box.GetOffsetPoint(Pt1); var pt2 = box.GetOffsetPoint(Pt2); #region 绘制相关矩形 GetRects(); foreach (var rect in _rects) { rect.Draw(g, box); } #endregion #region 绘制线段 using (Pen p = new Pen(ForeColor, BorderWidth) { DashStyle = Drawing.Drawing2D.DashStyle.Dot }) { if (ShowArrow) { float len = GetLength(pt1.X, pt1.Y, pt2.X, pt2.Y) * 0.2f; len = len < 2 ? 2 : len > 6 ? 6 : len; System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(len, len, true); p.CustomEndCap = lineArrow; } g.DrawLine(p, pt1, pt2); } #endregion }
private void Button_Click_2(object sender, RoutedEventArgs e) { var byteImage = GetImageByte(this.ScreenshotImage.Source); System.Drawing.Image image = (System.Drawing.Image)(BytesToImage(byteImage)); var startPoint = new Point(image.Width * 0.0730994152046784, image.Height * 0.130890052356021); var endPoint = new Point(image.Width * 0.219298245614035, image.Height * 0.392670157068063); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image); System.Drawing.Color color = System.Drawing.Color.Red; System.Drawing.Pen mypen = new System.Drawing.Pen(color, 8); //设置画笔的颜色及宽度 mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; //恢复实线 mypen.EndCap = System.Drawing.Drawing2D.LineCap.Custom; //定义线尾的样式为箭头 System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6, true); mypen.CustomEndCap = lineCap; g.DrawLine(mypen, 10, 30, 400, 800); byteImage = imageToByte(image); BitmapImage BitImage = new BitmapImage(); BitImage.BeginInit(); BitImage.StreamSource = new MemoryStream(byteImage); BitImage.EndInit(); ScreenshotImage.Source = BitImage; }
/// <summary> /// Метод відображення лінії ребра /// </summary> /// <param name="first">Початок ребра</param> /// <param name="second">Кінець ребра</param> /// <param name="isOrtagonal">Чи ортагональний граф</param> /// <param name="color">Колір лінії</param> /// <returns>Зображення з лінією</returns> private Image drawOnlyLine(Vertex first, Vertex second, bool isOrtagonal, Color color) { LinePen.Color = color; if (color.Equals(Color.Red)) { LinePen.Width = 3; } else { LinePen.Width = 2; } if (isOrtagonal) { System.Drawing.Drawing2D.CustomLineCap custom = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 6); LinePen.EndCap = System.Drawing.Drawing2D.LineCap.Custom; LinePen.CustomEndCap = custom; } else { LinePen.StartCap = System.Drawing.Drawing2D.LineCap.NoAnchor; LinePen.EndCap = System.Drawing.Drawing2D.LineCap.NoAnchor; } Vertex onCircule = CalculateDotPosition(second, first); draw.DrawLine(LinePen, first.X, first.Y, onCircule.X, onCircule.Y); drawOnlyDot(first); drawOnlyDot(second); return(image); }
public PlottableScatter PlotArrow( double tipX, double tipY, double baseX, double baseY, double lineWidth = 5, float arrowheadWidth = 3, float arrowheadLength = 3, Color?color = null, string label = null ) { var arrow = PlotScatter( xs: new double[] { baseX, tipX }, ys: new double[] { baseY, tipY }, color: color, lineWidth: lineWidth, label: label, markerSize: 0 ); var arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(arrowheadWidth, arrowheadLength, isFilled: true); arrow.penLine.CustomEndCap = arrowCap; arrow.penLine.StartCap = System.Drawing.Drawing2D.LineCap.Flat; return(arrow); }
private void InitCharaterGraph() { //根据给定颜色(LightGray)填充图像的矩形区域 (背景) objGraphics.DrawRectangle(new Pen(BorderColor, 1), 0, 0, Width, Height); objGraphics.FillRectangle(new SolidBrush(BgColor), 1, 1, Width - 2, Height - 2); //画X轴,pen,x1,y1,x2,y2 注意图像的原始X轴和Y轴计算是以左上角为原点,向右和向下计算的 //objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor), 1), 45, Height - 45, Width - 5, Height - 45); System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6, true); Pen redArrowPen = new Pen(AxisColor, 1); redArrowPen.CustomEndCap = lineCap; objGraphics.DrawLine(redArrowPen, 30, Height - 20, Width - 5, Height - 20); //画Y轴,pen,x1,y1,x2,y2 //objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor), 1), 45, Height - 45, 45, 5); objGraphics.DrawLine(redArrowPen, 30, Height - 20, 30, 15); redArrowPen.Dispose(); //初始化轴线说明文字 SetAxisText(ref objGraphics); //初始化标题 objGraphics.DrawString(this.TitleText, new Font("宋体", 16), new SolidBrush(TitelColor), new Point(AxisWith / 2 - 120, 1)); }
public override void Refresh() { Pen pn; Pen pn2; System.Drawing.Drawing2D.AdjustableArrowCap arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3, true); if (IsSelected) { pn = new Pen(Color.Gray, 3); pn2 = new Pen(Color.DarkGray, 3); } else { pn = new Pen(Color.LightGray, 3); pn2 = new Pen(Color.Gray, 3); } pn.CustomEndCap = arrowCap; pn.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pn2.CustomEndCap = arrowCap; pn2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; OffsetMyPoints(1); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyPoints(-1); myDiagram.drawingSurface.DrawLines(pn, myPts); pn.Dispose(); pn2.Dispose(); arrowCap.Dispose(); }
void Draw(System.Drawing.Graphics g, System.Drawing.Drawing2D.AdjustableArrowCap customStartCap, System.Drawing.Drawing2D.AdjustableArrowCap customEndCap) { System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer(); System.Drawing.Drawing2D.Matrix myMatrix = g.Transform; float X = (float)this.X; float Y = (float)this.Y; if (m_Rotation != 0) { myMatrix.RotateAt((float)m_Rotation, new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; } System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth); // put startcaps and endcaps on lines if (customStartCap != null) { myPen.CustomStartCap = customStartCap; } if (customEndCap != null) { myPen.CustomEndCap = customEndCap; } g.DrawLine(myPen, X, Y, X + m_Size.Width, Y + m_Size.Height); g.EndContainer(gContainer); }
private void wava_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; foreach (var rect in points) { x1 = rect.X; y1 = rect.Y; x2 = rect.Width; y2 = rect.Height; g.DrawLine(pen1, (int)x1, (int)y1, (int)x2, (int)y2); } g.DrawLine(pen2, 30, 220, 30, 217); g.DrawLine(pen2, 40, 220, 40, 217); g.DrawLine(pen2, 50, 220, 50, 217); g.DrawLine(pen2, 60, 220, 60, 217); g.DrawLine(pen2, 70, 220, 70, 215); g.DrawLine(pen2, 80, 220, 80, 217); g.DrawLine(pen2, 90, 220, 90, 217); g.DrawLine(pen2, 100, 220, 100, 217); g.DrawLine(pen2, 110, 220, 110, 217); g.DrawLine(pen2, 120, 220, 120, 215); g.DrawLine(pen2, 130, 220, 130, 217); g.DrawLine(pen2, 140, 220, 140, 217); g.DrawLine(pen2, 150, 220, 150, 217); g.DrawLine(pen2, 160, 220, 160, 217); g.DrawLine(pen2, 170, 220, 170, 215); g.DrawLine(pen2, 180, 220, 180, 217); g.DrawLine(pen2, 190, 220, 190, 217); g.DrawLine(pen2, 200, 220, 200, 217); g.DrawLine(pen2, 210, 220, 210, 217); g.DrawLine(pen2, 220, 220, 220, 215); g.DrawLine(pen2, 230, 220, 230, 217); g.DrawLine(pen2, 20, 60, 25, 60); g.DrawLine(pen2, 20, 140, 25, 140); System.Drawing.Drawing2D.AdjustableArrowCap linecap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6, false); // Pen pen2 = new Pen(Color.Blue, 3); // pen2.CustomEndCap = linecap; g.DrawLine(pen2, 20, 220, 20, 0); g.DrawLine(pen2, 20, 220, 250, 220); g.DrawLine(pen2, 20, 0, 10, 10); g.DrawLine(pen2, 20, 0, 30, 10); g.DrawLine(pen2, 250, 220, 240, 210); g.DrawLine(pen2, 250, 220, 240, 230); Font fnt = new Font("Verdana", 6); g.DrawString("0.8", fnt, new SolidBrush(Color.Black), 0, 60); g.DrawString("0.4", fnt, new SolidBrush(Color.Black), 0, 140); g.DrawString("5", fnt, new SolidBrush(Color.Black), 70, 230); g.DrawString("10", fnt, new SolidBrush(Color.Black), 120, 230); g.DrawString("15", fnt, new SolidBrush(Color.Black), 170, 230); }
static Pen getPenArrow() { System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 6, true); Pen RedPen = new Pen(Color.Black, 2); RedPen.CustomEndCap = lineCap; return RedPen; }
public void paint_me(ref Graphics gr0) // this function is used to paint the points { Pen edge_pen = new Pen(Color.DarkOrange, 1); gr0.DrawLine(edge_pen, mid_pt.get_point(), end_pt.get_point()); System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3); edge_pen.CustomEndCap = bigArrow; gr0.DrawLine(edge_pen, start_pt.get_point(), mid_pt.get_point()); }
internal override void Draw(Graphics g, ImageBox box) { if (!Visible || this.IsEmpty()) { return; } var pt1 = box.GetOffsetPoint(Pt1); var pt2 = box.GetOffsetPoint(Pt2); #region 绘制相关矩形 GetRects(); foreach (var rect in _rects) { rect.Draw(g, box); } #endregion #region 绘制选中状态 //if (Selected) //{ #region 绘制线段 using (Pen p = new Pen(ForeColor, BorderWidth) { DashStyle = Drawing.Drawing2D.DashStyle.Dot }) { if (ShowArrow) { float len = GetLength(pt1.X, pt1.Y, pt2.X, pt2.Y) * 0.2f; len = len < 2 ? 2 : len > 6 ? 6 : len; System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(len, len, true); p.CustomEndCap = lineArrow; } g.DrawLine(p, pt1, pt2); } #endregion #region 绘制锚点 if (Selected) { int halfDragHandleSize = DragHandleSize / 2; int cx = Convert.ToInt32((pt1.X + pt2.X) / 2) - halfDragHandleSize; int cy = Convert.ToInt32((pt1.Y + pt2.Y) / 2) - halfDragHandleSize; DragHandleCollection[DragHandleAnchor.MiddleLeft].Bounds = new Rectangle((int)pt1.X - halfDragHandleSize, (int)pt1.Y - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize); DragHandleCollection[DragHandleAnchor.MiddleCenter].Bounds = new Rectangle(cx, cy, this.DragHandleSize, this.DragHandleSize); DragHandleCollection[DragHandleAnchor.MiddleRight].Bounds = new Rectangle((int)pt2.X - halfDragHandleSize, (int)pt2.Y - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize); DrawDragHandles(g); } #endregion //} #endregion }
// //用于动态展示 private void drawArrow2() { System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6, true); Pen RedPen = new Pen(pen1.Color, pen1.Width); pictureBox1.Refresh(); RedPen.CustomEndCap = lineCap; Graphics g = pictureBox1.CreateGraphics(); g.DrawLine(RedPen, p1, p2); }
private void DrawArrow(DrawListViewItemEventArgs e, int x1, int y1, int x2, int y2) { System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3, true); Pen p = new Pen(Color.LightBlue, 3); p.CustomEndCap = lineCap; p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;//恢复实线 e.Graphics.DrawLine(p, x1, y1, x2, y2); p.Dispose(); }
//真正写入image private void drawArrow() { System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6, true); Pen RedPen = new Pen(pen1.Color, pen1.Width); pictureBox1.Refresh(); RedPen.CustomEndCap = lineCap; drawG.DrawLine(RedPen, p1, p2); pictureBox1.Image = tempImg; }
private static void DrawArrow(PaintEventArgs e, Position a, Position b, Color c) { System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5); System.Drawing.Pen myBrush = new Pen(c, strokeWidth); myBrush.CustomEndCap = bigArrow; // myBrush.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; Position z = GetArrowEnd(b, a, size / 2); e.Graphics.DrawLine(myBrush, (int)a.X + offsetX, (int)a.Y + offsetY, (int)z.X + offsetX, (int)z.Y + offsetY); myBrush.Dispose(); }
public CubicBezier(UnitPoint point, UnitPoint endpoint, float width, Color color) { m_p1 = point; m_p2 = endpoint; m_useStartArrow = false; m_useEndArrow = false; UpdateCtrlPts(); Width = width; Color = color; Selected = false; m_guid = System.Guid.NewGuid().ToString(); m_arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5); }
public void drawEdge(PictureBox panel) { Graphics graphics = panel.CreateGraphics(); System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5); Pen pen = new Pen(colorEdge, 2.0F); pen.CustomEndCap = bigArrow; PointF startPoint = new PointF(startNode.location.X + Node.size/2, startNode.location.Y + Node.size/2); PointF endPoint = new PointF( endNode.location.X + Node.size/2, endNode.location.Y + Node.size/2); double R = Math.Sqrt(Math.Pow(startPoint.X - endPoint.X, 2.0) + Math.Pow(startPoint.Y - endPoint.Y, 2.0)); double size = Node.size / 2; endPoint.X = (float)((startPoint.X + ((R - size) / size) * endPoint.X) / (R / size)); endPoint.Y = (float)((startPoint.Y + ((R - size) / size) * endPoint.Y) / (R / size)); graphics.DrawLine(pen, startPoint, endPoint); panel.Controls.Add(label); }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (EM == EditMode.None) { return; } EndPoint = GetNearestValidPoint(e); if (!StartEdit && EM != EditMode.GanJian && TS.GetNodeIndex(ToGridPointF(EndPoint)) == -1) { pictureBox1.Image = currentBmp; return; } destBmp.Dispose(); destBmp = (Bitmap)currentBmp.Clone(); Graphics g = Graphics.FromImage(destBmp); if (!StartEdit) { DrawPointCircle(ref g, EndPoint); } else { if (EM == EditMode.GanJian) { g.DrawLine(Pens.DimGray, StartPoint, EndPoint); DrawPointCircle(ref g, EndPoint); } else if (EM == EditMode.HeZai) { Pen p = new Pen(Color.Red, 1.5f); System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5, false); p.CustomStartCap = lineArrow; g.DrawLine(p, StartPoint, EndPoint); p.Dispose(); } else { if (TS.GetNodeIndex(ToGridPointF(EndPoint)) != -1) { DrawPointCircle(ref g, EndPoint); } } } pictureBox1.Image = destBmp; g.Dispose(); }
// vẽ Edge với pen tùy chọn public void drawEdge(Edge e, Brush br) { Graphics g = panel5.CreateGraphics(); var f = new Font("Arial", 9); Pen pen2 = new Pen(br, 5); System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5); pen2.CustomEndCap = bigArrow; Point p1 = new Point(e.startNode.x, e.startNode.y); Point p2 = new Point(e.endNode.x, e.endNode.y); g.DrawLine(pen2, p1, p2); int xx = (e.startNode.x + e.endNode.x) / 2 - 15; int yy = (e.startNode.y + e.endNode.y) / 2 - 15; g.DrawString(e.weight.ToString(), f, Brushes.Black, xx, yy); }
public ControlDrawArea(DrawArea drawArea, FormDlgMain formDlg) { _drawArea1 = drawArea; FormDlgMain formDlgMain = formDlg; _drawArea1.DrawingEnd += new MyEvent1(DisplayArea); _drawArea1.RectSeclecting += new RecipeEvent2(Rect_Selected); _cusCap = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5, false); _drawArea1.Owner = formDlgMain; _nowGraphicsList = new GraphicsList(); //_drawArea1.Initialize(formDlgMain); _drawArea1.Initialize(formDlgMain, ref _nowGraphicsList); _rectArray = new DrawList(); }
private void panelDiagram_Paint(object sender, PaintEventArgs e) { foreach (Control ctrl in panelDiagram.Controls) { if (ctrl.Name.Equals("TableBox", StringComparison.OrdinalIgnoreCase)) { TableBox tableBox = (TableBox)ctrl; CTable table = tableBox.Table; //找主表 List <CBaseObject> lstCol = table.ColumnMgr.GetList(); foreach (CBaseObject obj in lstCol) { CColumn col = (CColumn)obj; if (col.ColType == ColumnType.ref_type) { CTable table2 = (CTable)Program.Ctx.TableMgr.Find(col.RefTable); foreach (Control ctrl2 in panelDiagram.Controls) { if (ctrl2.Name.Equals("TableBox", StringComparison.OrdinalIgnoreCase)) { TableBox tableBox2 = (TableBox)ctrl2; if (table2 == tableBox2.Table) { //画关联线 System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); Pen RedPen = new Pen(Color.Red, 1); RedPen.CustomEndCap = lineCap; int x1 = tableBox.Left; int y1 = tableBox.Top + tableBox.Height / 2; int x2 = tableBox2.Left; int y2 = tableBox2.Top + tableBox2.Height / 2; e.Graphics.DrawLine(RedPen, x1, y1, x2, y2); } } } } } } } }
internal override void Draw(Graphics g, ImageBox box) { if (!Visible || this.IsEmpty()) { return; } using (Pen p = new Pen(ForeColor, AutoChangeSize ? BorderWidth * box.ZoomFactor : BorderWidth)) { if (ShowArrow) { float len = 8 * box.ZoomFactor; System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(len, len, false); p.CustomEndCap = lineArrow; } var pt1 = box.GetOffsetPoint(Pt1); var pt2 = box.GetOffsetPoint(Pt2); g.DrawLine(p, pt1, pt2); } }
private void btnRuta_Click(object sender, EventArgs e) { string codigo; string desde; string hasta; codigo = Microsoft.VisualBasic.Interaction.InputBox("Ingrese el Codigo de Ruta", "Registro de Datos", "", 300, 300); desde = Microsoft.VisualBasic.Interaction.InputBox("Codigo de Punto ACTUAL", "Registro de Datos", "", 300, 300); hasta = Microsoft.VisualBasic.Interaction.InputBox("Codigo de Punto donde se dirije", "Registro de Datos", "", 300, 300); GMapOverlay Ruta = new GMapOverlay("GuiaRuta"); Pen estilo = new Pen(Brushes.DarkBlue, 2); System.Drawing.Drawing2D.AdjustableArrowCap flecha = new System.Drawing.Drawing2D.AdjustableArrowCap(10, 10); estilo.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; estilo.CustomEndCap = flecha; puntos = new List<PointLatLng>(); puntos.Add(new PointLatLng(Desde(desde).Item1, Desde(desde).Item2)); puntos.Add(new PointLatLng(Hasta(hasta).Item1, Hasta(hasta).Item2)); GMapRoute puntosRuta = new GMapRoute(puntos, "Ruta"); puntosRuta.Stroke = estilo; Ruta.Routes.Add(puntosRuta); gMapControl1.Overlays.Add(Ruta); ///////////////////////////// //actualizar el mapa gMapControl1.Zoom = gMapControl1.Zoom + 1; gMapControl1.Zoom = gMapControl1.Zoom - 1; double distance = puntosRuta.Distance; //txtdistancia.Text = Convert.ToString(distance) + " Km"; dt2.Rows.Add(codigo, desde, hasta, distance); }
internal override void Draw(Graphics g, ImageBox box) { if (!Visible || this.IsEmpty()) { return; } using (Pen p = new Pen(ForeColor, AutoChangeSize ? BorderWidth * box.ZoomFactor : BorderWidth)) { //绘制圆 var rect = GetRect(Sradius); var rect1 = box.GetOffsetRectangle(rect); g.DrawEllipse(p, rect1); rect = GetRect(Eradius); rect1 = box.GetOffsetRectangle(rect); g.DrawEllipse(p, rect1); //绘制箭头 PointF pt1 = PointF.Empty, pt2 = PointF.Empty; GetEdgePoint(out pt1, out pt2); float len = 8; System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(len, len, false); p.CustomEndCap = lineArrow; p.DashStyle = Drawing.Drawing2D.DashStyle.Dash; var pp1 = box.GetOffsetPoint(pt1); var pp2 = box.GetOffsetPoint(pt2); var cpt = box.GetOffsetPoint(Cpt); for (int i = 0; i < 13; i++) { g.TranslateTransform(cpt.X, cpt.Y); g.RotateTransform(30); g.TranslateTransform(-cpt.X, -cpt.Y); g.DrawLine(p, pp1, pp2); } g.ResetTransform(); } }
protected override void Rysuj(Graphics g) { System.Drawing.Drawing2D.AdjustableArrowCap arrowcap = new System.Drawing.Drawing2D.AdjustableArrowCap(7, 7, false); //tworzy strzalke na koncu linii using (Pen pen = new Pen(kolor)) //rysowanie kratki ukladu { for (int i = -400; i <= 400; i = i + 50) { if (i != 0) { g.DrawLine(pen, x - 400, y - i, x + 400, y - i); g.DrawLine(pen, x - i, y - 400, x - i, y + 400); } } } kolor = Color.Black; using (Pen pen = new Pen(kolor, 3)) //rysowanie osi układu { pen.CustomEndCap = arrowcap; g.DrawLine(pen, x - 400, y, x + 400, y); g.DrawLine(pen, x, y + 400, x, y - 400); } }
public override void Refresh() { System.Drawing.Drawing2D.AdjustableArrowCap arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 5, true); Pen pn; Pen pn2; Brush drawBrush = Brushes.MistyRose; if (IsSelected) { pn = new Pen(Color.Firebrick, 3); pn2 = new Pen(Color.Firebrick, 3); } else { pn = new Pen(Color.MistyRose, 3); pn2 = new Pen(Color.LightSteelBlue, 3); } pn.CustomEndCap = arrowCap; pn2.CustomEndCap = arrowCap; RectangleF ConnectorBox = new RectangleF(); Point cntr = new Point(); if (myACD != null) { cntr = new Point((myPts[0].X + myPts[myPts.Length - 1].X) / 2 - 12, (myPts[0].Y + myPts[myPts.Length - 1].Y) / 2 - 12); SizeF boxSize = new SizeF(19, 19); ConnectorBox = new RectangleF(cntr, boxSize); myDiagram.drawingSurface.DrawRectangle(myDiagram.PenSteelBlue, ConnectorBox.X, ConnectorBox.Y, ConnectorBox.Width, ConnectorBox.Height); } OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(-2); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn, myPts); if (myACD != null) { StringFormat sformat = new StringFormat(); sformat.Alignment = StringAlignment.Center; sformat.LineAlignment = StringAlignment.Center; myDiagram.drawingSurface.FillRectangle(drawBrush, ConnectorBox); myDiagram.drawingSurface.DrawImage(Properties.Resources.power_off, ConnectorBox.X + 2, ConnectorBox.Y + 2, 16, 16); if (myACD.RowState == System.Data.DataRowState.Modified) { myDiagram.drawingSurface.DrawString("* [edited] *", myDiagram.SelectedFont, Brushes.Black, cntr.X + 8, cntr.Y - 8, sformat); } sformat.Dispose(); } pn.Dispose(); pn2.Dispose(); arrowCap.Dispose(); }
public override void Refresh() { if (myDiagram.DrawBFOnlyConnectors) { System.Drawing.Drawing2D.AdjustableArrowCap arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 5, true); Pen pn; Pen pn2; Brush drawBrush = Brushes.Orange; if (IsSelected) { pn = new Pen(Color.Firebrick, 3); pn2 = new Pen(Color.Firebrick, 3); } else { pn = new Pen(Color.Orange, 3); pn2 = new Pen(myDiagram.BrushDrawingSurface, 3); } pn.CustomEndCap = arrowCap; pn.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pn2.CustomEndCap = arrowCap; pn2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; Rectangle ConnectorBox = new Rectangle(); Point cntr = new Point((myPts[0].X + myPts[myPts.Length - 1].X) / 2 - 12, (myPts[0].Y + myPts[myPts.Length - 1].Y) / 2 - 7); string BoxText = ""; if (myACD != null && myACD.ACBFRow != null) { BoxText = myACD.ACBFRow.BFCode; SizeF boxSize = myDiagram.drawingSurface.MeasureString(BoxText, myDiagram.DrawFont); ConnectorBox = new Rectangle(cntr.X - 2, cntr.Y, (int)boxSize.Width + 1, (int)boxSize.Height); myDiagram.drawingSurface.DrawRectangle(myDiagram.PenSteelBlue, ConnectorBox); if (myPts[0].X == myPts[1].X) { myDiagram.drawingSurface.DrawImage(Properties.Resources.BFListCalendar, ConnectorBox.X - 17, ConnectorBox.Y - 1); } else { myDiagram.drawingSurface.DrawImage(Properties.Resources.BFListCalendar, ConnectorBox.X + (ConnectorBox.Width / 2) - 8, ConnectorBox.Y - 16); } } OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(-2); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn, myPts); if (myACD != null) { StringFormat sformat = new StringFormat(); sformat.Alignment = StringAlignment.Center; sformat.LineAlignment = StringAlignment.Center; myDiagram.drawingSurface.FillRectangle(myDiagram.BrushWhite, ConnectorBox); myDiagram.drawingSurface.DrawString(BoxText, myDiagram.DrawFont, myDiagram.BrushBlack, ConnectorBox, sformat); if (myACD.RowState == System.Data.DataRowState.Modified) { myDiagram.drawingSurface.DrawString("* [edited] *", myDiagram.SelectedFont, Brushes.Black, cntr.X + 8, cntr.Y - 8, sformat); } sformat.Dispose(); } pn.Dispose(); pn2.Dispose(); arrowCap.Dispose(); } }
private void imageProcessBox1_MouseMove(object sender, MouseEventArgs e) { m_ptCurrent = e.Location; //根据是否选择有工具决定 鼠标指针样式 if (imageProcessBox1.SelectedRectangle.Contains(e.Location) && HaveSelectedToolButton() && imageProcessBox1.IsDrawed) this.Cursor = Cursors.Cross; else if (!imageProcessBox1.SelectedRectangle.Contains(e.Location)) this.Cursor = Cursors.Default; if (imageProcessBox1.IsStartDraw && panel1.Visible) //在重置选取的时候 重置工具条位置(成立于移动选取的时候) this.SetToolBarLocation(); if (m_isStartDraw && m_bmpLayerShow != null) { //如果在区域内点下那么绘制相应图形 using (Graphics g = Graphics.FromImage(m_bmpLayerShow)) { int tempWidth = 1; if (toolButton2.IsSelected) tempWidth = 3; if (toolButton3.IsSelected) tempWidth = 5; Pen p = new Pen(colorBox1.SelectedColor, tempWidth); #region 绘制矩形 if (tBtn_Rect.IsSelected) { int tempX = e.X - m_ptOriginal.X > 0 ? m_ptOriginal.X : e.X; int tempY = e.Y - m_ptOriginal.Y > 0 ? m_ptOriginal.Y : e.Y; g.Clear(Color.Transparent); g.DrawRectangle(p, tempX - imageProcessBox1.SelectedRectangle.Left, tempY - imageProcessBox1.SelectedRectangle.Top, Math.Abs(e.X - m_ptOriginal.X), Math.Abs(e.Y - m_ptOriginal.Y)); imageProcessBox1.Invalidate(); } #endregion #region 绘制圆形 if (tBtn_Ellipse.IsSelected) { g.DrawLine(Pens.Red, 0, 0, 200, 200); g.Clear(Color.Transparent); g.DrawEllipse(p, m_ptOriginal.X - imageProcessBox1.SelectedRectangle.Left, m_ptOriginal.Y - imageProcessBox1.SelectedRectangle.Top, e.X - m_ptOriginal.X, e.Y - m_ptOriginal.Y); imageProcessBox1.Invalidate(); } #endregion #region 绘制箭头 if (tBtn_Arrow.IsSelected) { g.Clear(Color.Transparent); System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); p.CustomEndCap = lineArrow; g.DrawLine(p, (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location), (Point)((Size)m_ptCurrent - (Size)imageProcessBox1.SelectedRectangle.Location)); imageProcessBox1.Invalidate(); } #endregion #region 绘制线条 if (tBtn_Brush.IsSelected) { Point ptTemp = (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location); p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; g.DrawLine(p, ptTemp, (Point)((Size)e.Location - (Size)imageProcessBox1.SelectedRectangle.Location)); m_ptOriginal = e.Location; imageProcessBox1.Invalidate(); } #endregion p.Dispose(); } } }
public override void Refresh() { System.Drawing.Drawing2D.AdjustableArrowCap arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 3, true); System.Drawing.Drawing2D.AdjustableArrowCap arrowCap2 = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); Pen pn; Pen pn2; Font drawFont = myDiagram.DrawFont; Brush drawBrush = myDiagram.BrushWhite; Brush drawString = myDiagram.BrushBlack; Brush drawRole = myDiagram.BrushWhite; if (myACD != null) { if (myACD.ACBFRow != null && !myACD.ACBFRow.IsRoleCodeNull()) { System.Data.DataTable dtRole = UIHelper.AtMng.GetFile().Codes("RoleCode"); System.Data.DataRow[] drRole = dtRole.Select("RoleCode='" + myACD.ACBFRow.RoleCode + "'", ""); if (drRole.Length == 0) { dtRole = UIHelper.AtMng.GetFile().Codes("ContactType"); drRole = dtRole.Select("ContactTypeCode='" + myACD.ACBFRow.RoleCode + "'", ""); } if (!drRole[0].IsNull("WFBGColor")) { int intBrushColor = (int)drRole[0]["WFBGColor"]; if (intBrushColor != 0) { Color BrushColor = Color.FromArgb(intBrushColor); drawRole = new SolidBrush(BrushColor); } } } pn = new Pen(Color.White, 4); pn2 = new Pen(Color.LightSteelBlue, 4); pn.CustomEndCap = arrowCap; pn2.CustomEndCap = arrowCap; } else { pn = new Pen(Color.Yellow, 2); pn2 = new Pen(Color.LightSteelBlue, 2); pn.EndCap = System.Drawing.Drawing2D.LineCap.NoAnchor; pn2.EndCap = System.Drawing.Drawing2D.LineCap.NoAnchor; } if (IsSelected) { pn = new Pen(Color.Firebrick, 4); pn2 = new Pen(Color.White, 4); pn.CustomEndCap = arrowCap; pn2.CustomEndCap = arrowCap; drawFont = myDiagram.SelectedFont; drawBrush = myDiagram.BrushSelected; } Rectangle ConnectorBox = new Rectangle(); Point cntr = new Point((myPts[0].X + myPts[myPts.Length - 1].X) / 2 - 12, (myPts[0].Y + myPts[myPts.Length - 1].Y) / 2 - 7); bool drawBox = false; string BoxText = ""; if (myACD != null && !myACD.IsDescEngNull()) { BoxText = myACD.DescEng; SizeF boxSize = myDiagram.drawingSurface.MeasureString(BoxText, drawFont); if (myDiagram.HitStep(cntr) == null) { ConnectorBox = new Rectangle(cntr.X - 2, cntr.Y, (int)boxSize.Width + 1, (int)boxSize.Height); } else { Point nPoint = FindDrawLocation(cntr); ConnectorBox = new Rectangle(nPoint.X - 2, nPoint.Y, (int)boxSize.Width + 1, (int)boxSize.Height); } //ConnectorBox = new Rectangle(cntr.X-2, cntr.Y, (int)boxSize.Width+1, (int)boxSize.Height); myDiagram.drawingSurface.DrawRectangle(myDiagram.PenSteelBlue, ConnectorBox); drawBox = true; } if (myACD != null && myACD.ACBFRow != null) { BoxText = myACD.ACBFRow.BFCode; SizeF boxSize = myDiagram.drawingSurface.MeasureString(BoxText, drawFont); if (myDiagram.HitStep(cntr) == null) { ConnectorBox = new Rectangle(cntr.X - 2, cntr.Y, (int)boxSize.Width + 1, (int)boxSize.Height); } else { Point nPoint = FindDrawLocation(cntr); ConnectorBox = new Rectangle(nPoint.X - 2, nPoint.Y, (int)boxSize.Width + 1, (int)boxSize.Height); } myDiagram.drawingSurface.DrawRectangle(myDiagram.PenSteelBlue, ConnectorBox); if (myPts[0].X == myPts[1].X) { myDiagram.drawingSurface.DrawImage(Properties.Resources.act, ConnectorBox.X - 17, ConnectorBox.Y - 1); } else { myDiagram.drawingSurface.DrawImage(Properties.Resources.act, ConnectorBox.X + (ConnectorBox.Width / 2) - 8, ConnectorBox.Y - 16); } drawBox = true; } OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(-2); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn, myPts); if (drawBox) { StringFormat sformat = new StringFormat(); sformat.Alignment = StringAlignment.Center; sformat.LineAlignment = StringAlignment.Center; myDiagram.drawingSurface.FillRectangle(drawRole, ConnectorBox); myDiagram.drawingSurface.DrawString(BoxText, drawFont, drawString, ConnectorBox, sformat); if (myACD.RowState == System.Data.DataRowState.Modified) { myDiagram.drawingSurface.DrawString("* [edited] *", myDiagram.SelectedFont, Brushes.Black, cntr.X + 8, cntr.Y - 8, sformat); } sformat.Dispose(); } pn.Dispose(); pn2.Dispose(); arrowCap.Dispose(); }
private void imageProcessBox1_MouseMove(object sender, MouseEventArgs e) { m_ptCurrent = e.Location; //根据是否选择有工具决定 鼠标指针样式 if (imageProcessBox1.SelectedRectangle.Contains(e.Location) && HaveSelectedToolButton() && imageProcessBox1.IsDrawed) { this.Cursor = Cursors.Cross; } else if (!imageProcessBox1.SelectedRectangle.Contains(e.Location)) { this.Cursor = Cursors.Default; } if (imageProcessBox1.IsStartDraw && panel1.Visible) //在重置选取的时候 重置工具条位置(成立于移动选取的时候) { this.SetToolBarLocation(); } if (m_isStartDraw && m_bmpLayerShow != null) { //如果在区域内点下那么绘制相应图形 using (Graphics g = Graphics.FromImage(m_bmpLayerShow)) { int tempWidth = 1; if (toolButton2.IsSelected) { tempWidth = 3; } if (toolButton3.IsSelected) { tempWidth = 5; } Pen p = new Pen(colorBox1.SelectedColor, tempWidth); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; #region 绘制矩形 if (tBtn_Rect.IsSelected) { int tempX = e.X - m_ptOriginal.X > 0 ? m_ptOriginal.X : e.X; int tempY = e.Y - m_ptOriginal.Y > 0 ? m_ptOriginal.Y : e.Y; g.Clear(Color.Transparent); g.DrawRectangle(p, tempX - imageProcessBox1.SelectedRectangle.Left, tempY - imageProcessBox1.SelectedRectangle.Top, Math.Abs(e.X - m_ptOriginal.X), Math.Abs(e.Y - m_ptOriginal.Y)); imageProcessBox1.Invalidate(); } #endregion #region 绘制圆形 if (tBtn_Ellipse.IsSelected) { g.DrawLine(Pens.Red, 0, 0, 200, 200); g.Clear(Color.Transparent); g.DrawEllipse(p, m_ptOriginal.X - imageProcessBox1.SelectedRectangle.Left, m_ptOriginal.Y - imageProcessBox1.SelectedRectangle.Top, e.X - m_ptOriginal.X, e.Y - m_ptOriginal.Y); imageProcessBox1.Invalidate(); } #endregion #region 绘制箭头 if (tBtn_Arrow.IsSelected) { g.Clear(Color.Transparent); System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5, true); p.CustomEndCap = lineArrow; g.DrawLine(p, (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location), (Point)((Size)m_ptCurrent - (Size)imageProcessBox1.SelectedRectangle.Location)); imageProcessBox1.Invalidate(); } #endregion #region 绘制线条 if (tBtn_Brush.IsSelected) { Point ptTemp = (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location); p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; g.DrawLine(p, ptTemp, (Point)((Size)e.Location - (Size)imageProcessBox1.SelectedRectangle.Location)); m_ptOriginal = e.Location; imageProcessBox1.Invalidate(); } #endregion p.Dispose(); } } }
private void button15_Click(object sender, EventArgs e) { int min = Convert.ToInt16(textBox3.Text); int max = Convert.ToInt16(textBox4.Text); //通过画刷进行填充 Graphics myg = pictureBox1.CreateGraphics(); Brush bkbrush = new SolidBrush(Color.White); myg.FillRectangle(bkbrush, 0, 0, 741, 628); Color bkColor = Color.FromArgb(255, 255, 215, 0); Brush bkbrush1 = new SolidBrush(bkColor); int interval = 80; int dx = 60, dy = 50; int y = 20; int time = 0; bool direction = true; System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); SingleListNodeClass <int> p = m_SingleList.Head; for (int i = 0; i <= m_SingleList.Length; i++) { int x = interval * time + 20; if (x > 740 - interval && direction == true) { x -= interval; y += interval; direction = false; } else if (x < 20 && direction == false) { x += interval; y += interval; direction = true; } if (direction == true) { time += 1; } else { time -= 1; } if (p.Data <= Math.Max(max, min) && p.Data >= Math.Min(max, min)) { Brush t = new SolidBrush(Color.Pink); myg.FillRectangle(t, (float)(x), (float)(y), dx, dy);//画填充矩形 } else { myg.FillRectangle(bkbrush1, (float)(x), (float)(y), dx, dy);//画填充矩形 } //画箭头 Pen penLine = new Pen(Color.Red, 1); penLine.CustomEndCap = lineCap; Point arrowp1 = new Point(0, 0); Point arrowp2 = new Point(0, 0); if (direction == true && i != 0) { arrowp1 = new Point(x + dx - interval, y + dy / 2); arrowp2 = new Point(x, y + dy / 2); } else if (direction == false) { arrowp1 = new Point(x + interval, y + dy / 2); arrowp2 = new Point(x + dx, y + dy / 2); } myg.DrawLine(penLine, arrowp1, arrowp2); Pen pen2 = new Pen(Color.Red, 1); if (direction == false && x + interval > 720) { Point pp1 = new Point(x + interval, y - interval + dy / 2); Point pp2 = new Point(x + interval, y + dy / 2); myg.DrawLine(pen2, pp1, pp2); pp2 = pp1; pp1 = new Point(x + dx, y - interval + dy / 2); myg.DrawLine(pen2, pp1, pp2); time -= 1; } else if (direction == true && x <= 30 && i != 0) { Point pp1 = new Point(x - interval + dx, y - interval + dy / 2); Point pp2 = new Point(x - interval + dx, y + dy / 2); myg.DrawLine(pen2, pp1, pp2); pp2 = pp1; pp1 = new Point(x, y - interval + dy / 2); myg.DrawLine(pen2, pp1, pp2); time += 1; } //画四周四条边 Pen pen1 = new Pen(Color.Red, 1); Point p1 = new Point(x, y); Point p2 = new Point(x, y + dy); myg.DrawLine(pen1, p1, p2); p1 = p2; p2 = new Point(x + dx, y + dy); myg.DrawLine(pen1, p1, p2); p1 = p2; p2 = new Point(x + dx, y); myg.DrawLine(pen1, p1, p2); p1 = p2; p2 = new Point(x, y); myg.DrawLine(pen1, p1, p2); //显示字符串 string str = Convert.ToString(p.Data); if (i == 0) { str = "head"; } p = p.Next; Font font = new Font("Arial", 12); SolidBrush b1 = new SolidBrush(Color.Blue); StringFormat sf1 = new StringFormat(); myg.DrawString(str, font, b1, x + 18, y + 15, sf1); } button11.Text = Convert.ToString(m_SingleList.Currrent.GetHashCode()); button12.Text = Convert.ToString(m_SingleList.Currrent.Data); if (m_SingleList.Currrent.Next == null) { button13.Text = "null"; } else { button13.Text = Convert.ToString(m_SingleList.Currrent.Next.GetHashCode()); } }
//计算线性拟合的标准曲线 private void calclateStd(Graphics g) { //计算标准曲线 List<PointF> stdPoints = new List<PointF>();//保存标准曲线上的点 //lambda表达式 : double变为float格式 Func<double, float> double2Float = x => float.Parse(x.ToString()); //整理出标准品数据,用字典实现conc唯一性 int std_count = 0; Dictionary<double, List<Info>> std = new Dictionary<double, List<Info>>(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 12; j++) { Info info = tpl[i, j]; List<Info> infoPlus = new List<Info>(); if (info != null && info.well_class == "std") { //增加od属性 info.well_od = od[i, j]; //整合到数据中 if (std.ContainsKey(info.well_conc)) { //如果存在,则先获得od值,然后增加 infoPlus = std[info.well_conc]; infoPlus.Add(info); std.Add(info.well_conc, infoPlus); } else { //首次增加 std_count++; infoPlus.Add(info); std.Add(info.well_conc, infoPlus); } } } } //整理x和y数组 double[] arr_x = new double[std_count];//conc double[] arr_y = new double[std_count];//od int std_i = 0;//最大值为 std_count foreach (double conc in std.Keys) { //MessageBox.Show(conc.ToString()); arr_x[std_i] = conc; List<Info> list=std[conc]; int od_counter=0; double od_sum = 0; foreach(Info info in list) { double temp = double2Float(info.well_od); od_sum += temp; od_counter++; //保存标准曲线上的点 stdPoints.Add(new PointF(double2Float(conc), double2Float(temp))); } arr_y[std_i] = od_sum / od_counter;//计算od的平均值 std_i++; } //输出数组 //showArray(arr_x); this.richTextBox1.Text += "\r\r"; //showArray(arr_y); //拟合计算============================================================================ int Pointlen = arr_x.Length; //拟合,返回参数列表 Double[] paras = CurveFit.MultiLine(arr_x, arr_y, Pointlen,1); //输出结果 //y=a0+a1*x 返回值则为a0 a1 int len = paras.Length; string str = ""; for (int i = 0; i < len; i++) { str += paras[i].ToString() + "\r\n"; } //显示结果 this.richTextBox1.Text += str; //由参数计算回算测量值============================================= double a0 = paras[0], a1 = paras[1]; double rss = 0, tss = 0;//残差平方和,总平方和 double[] arrX2 = new double[Pointlen];//用于浓度回算 double[] arrY2 = new double[Pointlen];//用于计算RSqure for (int i = 0; i < Pointlen; i++) { arrX2[i] = (arr_y[i] - a0) / a1; arrY2[i] = a0 + a1 * arr_x[i]; rss += Math.Pow(arr_y[i] - arrY2[i], 2); tss += Math.Pow(arr_y[i], 2); } //计算R^2 double RSqure = 1 - rss / tss; //this.richTextBox1.Text += "\r\nRSqure=" + RSqure; this.label2.Text = RSqure.ToString(); //==========================================================画图 basic //计算最值 double[] xM = getMinMax(arr_x); double[] yM = getMinMax(arr_y); //当前画布最值 double pWidth = this.pictureBox1.Width; double pHeight = this.pictureBox1.Height; //this.richTextBox1.Text += "\r\r画布尺寸(" + pWidth + "," + pHeight + "); \r"; //坐标轴范围 double x_span=xM[1]-xM[0]; double y_span=yM[1]-yM[0]; //lambda表达式 : 做坐标变换, Func<double, double> getAjustX = x => 20+ 0.9 * (x - xM[0]) * pWidth / x_span; Func<double, double> getAjustY = y => -20 + pHeight - 0.9 * (y - yM[0]) * pHeight / y_span; //纵轴倒置 //==========================================================画图 坐标轴 //定义铅笔 Pen pen1 = new Pen(Color.Black, 1);//画坐标轴,带箭头 Pen pen2 = new Pen(Color.Black, 1);//画刻度 Pen pen3 = new Pen(Color.LightGray, 1);//画背景虚线 pen3.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; //定义铅笔的头部箭头 System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); pen1.CustomEndCap = lineArrow; //--------------------定义坐标轴刻度 //坐标轴刻度 - 先按照 10格 double x_kedu =Math.Ceiling( x_span/10 );//刻度 double y_kedu = Math.Ceiling(y_span / 10); double x_o = xM[0] + x_kedu*0.5;//坐标轴所在位置 double y_o = yM[0] + y_kedu*0.6; //--------------------画坐标轴 //定义坐标点-x轴 PointF px1 = new PointF(0, double2Float(getAjustY(y_o))); PointF px2 = new PointF(double2Float(getAjustX(xM[1])), double2Float(getAjustY(y_o))); //定义坐标点-y轴 PointF py1 = new PointF(double2Float(getAjustX(x_o)), double2Float(pHeight)); PointF py2 = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(yM[1]))); //画坐标轴 g.DrawLine(pen1, px1, px2);//x g.DrawLine(pen1, py1, py2);//y //--------------------画坐标轴刻度 double x_axis = xM[0]; double y_axis = yM[0]; int ke_height = 6;//刻度尺寸 int font_size = 8; Font font = new Font("微软雅黑", font_size);//刻度字体 Brush brush=new SolidBrush(Color.Black);//用笔刷定义刻度字体颜色 PointF kedu_point;// = new PointF();//刻度的坐标 //坐标标度如果太大,则用科学技术法表示 Func<double, string> num2String = d => Int64.Parse(d.ToString()).ToString("E2"); //保留4位有效数字 //x轴刻度 while (x_axis < xM[1]) { //刻度向右递增 x_axis += x_kedu; //定义刻度线的首尾点 PointF px_k1 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(y_o)) - ke_height); PointF px_k2 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(y_o))); //画刻度 g.DrawLine(pen2, px_k1, px_k2); //画背景虚线 PointF px_k3 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(yM[0]))); PointF px_k4 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(yM[1]))); g.DrawLine(pen3, px_k3, px_k4); //标上刻度 kedu_point = new PointF(double2Float(getAjustX(x_axis)) - font_size, double2Float(getAjustY(y_o))); g.DrawString(x_axis.ToString(), font, brush,kedu_point); if (x_axis > 1000) { g.DrawString(num2String(x_axis), font, brush, kedu_point); } else { g.DrawString(x_axis.ToString(), font, brush, kedu_point); } } //y轴刻度 while (y_axis < yM[1]) { //刻度向右递增 y_axis += y_kedu; //定义刻度线的首尾点 PointF py_k1 = new PointF(double2Float(getAjustX(x_o)) + ke_height, double2Float(getAjustY(y_axis))); PointF py_k2 = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(y_axis))); //画刻度 g.DrawLine(pen2, py_k1, py_k2); //画背景虚线 PointF py_k3 = new PointF(double2Float(getAjustX(xM[0])), double2Float(getAjustY(y_axis))); PointF py_k4 = new PointF(double2Float(getAjustX(xM[1])), double2Float(getAjustY(y_axis))); g.DrawLine(pen3, py_k3, py_k4); //标上刻度 int y_axis_len = y_axis.ToString().Length; //kedu_point = new PointF(double2Float(getAjustX(x_o)) - y_axis_len * font_size, double2Float(getAjustY(y_axis))); kedu_point = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(y_axis))); if (y_axis > 1000) { g.DrawString(num2String(y_axis), font, brush, kedu_point); } else { g.DrawString(y_axis.ToString(), font, brush, kedu_point);//num2String } } //==========================================================画标注 主标题和坐标注释 g.DrawString("线性拟合标准曲线", new Font("宋体", 10), new SolidBrush(Color.Black), new Point(Width / 4, 10)); //==========================================================画图 拟合曲线 //细分点数 int dot_num = 10; List<PointF> pointFList = new List<PointF>(); //计算拟合出来的点 double[] xp = new double[dot_num]; double[] yp = new double[dot_num]; for (int i = 0; i < dot_num; i++) { //生成点 xp[i] = xM[0] + i * x_span / dot_num; yp[i] = a0 + a1 * xp[i]; //针对当前画布调整 xp[i] = double2Float(getAjustX(xp[i])); yp[i] = double2Float(getAjustY(yp[i])); //记录曲线 pointFList.Add( new PointF(double2Float( xp[i] ), double2Float( yp[i]))); } //画很多线 - 很多点连起来就是一条直线 myDraw.DrawLine(g, pointFList); //==========================================================画图 std原始点 //画std原始点 //myDraw.DrawPoints(g, xp, yp,1,true); PointF p = new PointF(); int dot_radius = 6;//空心点的大小 for (int i = 0; i < stdPoints.Count; i++) { p = stdPoints[i]; p.X = double2Float(getAjustX(p.X)); p.Y = double2Float(getAjustY(p.Y)); g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, dot_radius, dot_radius); } }
//计算线性拟合的标准曲线 private void calclateStd(Graphics g) { //计算标准曲线 List <PointF> stdPoints = new List <PointF>();//保存标准曲线上的点 //lambda表达式 : double变为float格式 Func <double, float> double2Float = x => float.Parse(x.ToString()); //整理出标准品数据,用字典实现conc唯一性 int std_count = 0; Dictionary <double, List <Info> > std = new Dictionary <double, List <Info> >(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 12; j++) { Info info = tpl[i, j]; List <Info> infoPlus = new List <Info>(); if (info != null && info.well_class == "std") { //增加od属性 info.well_od = od[i, j]; //整合到数据中 if (std.ContainsKey(info.well_conc)) { //如果存在,则先获得od值,然后增加 infoPlus = std[info.well_conc]; infoPlus.Add(info); std.Add(info.well_conc, infoPlus); } else { //首次增加 std_count++; infoPlus.Add(info); std.Add(info.well_conc, infoPlus); } } } } //整理x和y数组 double[] arr_x = new double[std_count]; //conc double[] arr_y = new double[std_count]; //od int std_i = 0; //最大值为 std_count foreach (double conc in std.Keys) { //MessageBox.Show(conc.ToString()); arr_x[std_i] = conc; List <Info> list = std[conc]; int od_counter = 0; double od_sum = 0; foreach (Info info in list) { double temp = double2Float(info.well_od); od_sum += temp; od_counter++; //保存标准曲线上的点 stdPoints.Add(new PointF(double2Float(conc), double2Float(temp))); } arr_y[std_i] = od_sum / od_counter;//计算od的平均值 std_i++; } //输出数组 //showArray(arr_x); this.richTextBox1.Text += "\r\r"; //showArray(arr_y); //拟合计算============================================================================ int Pointlen = arr_x.Length; //拟合,返回参数列表 Double[] paras = CurveFit.MultiLine(arr_x, arr_y, Pointlen, 1); //输出结果 //y=a0+a1*x 返回值则为a0 a1 int len = paras.Length; string str = ""; for (int i = 0; i < len; i++) { str += paras[i].ToString() + "\r\n"; } //显示结果 this.richTextBox1.Text += str; //由参数计算回算测量值============================================= double a0 = paras[0], a1 = paras[1]; double rss = 0, tss = 0; //残差平方和,总平方和 double[] arrX2 = new double[Pointlen]; //用于浓度回算 double[] arrY2 = new double[Pointlen]; //用于计算RSqure for (int i = 0; i < Pointlen; i++) { arrX2[i] = (arr_y[i] - a0) / a1; arrY2[i] = a0 + a1 * arr_x[i]; rss += Math.Pow(arr_y[i] - arrY2[i], 2); tss += Math.Pow(arr_y[i], 2); } //计算R^2 double RSqure = 1 - rss / tss; //this.richTextBox1.Text += "\r\nRSqure=" + RSqure; this.label2.Text = RSqure.ToString(); //==========================================================画图 basic //计算最值 double[] xM = getMinMax(arr_x); double[] yM = getMinMax(arr_y); //当前画布最值 double pWidth = this.pictureBox1.Width; double pHeight = this.pictureBox1.Height; //this.richTextBox1.Text += "\r\r画布尺寸(" + pWidth + "," + pHeight + "); \r"; //坐标轴范围 double x_span = xM[1] - xM[0]; double y_span = yM[1] - yM[0]; //lambda表达式 : 做坐标变换, Func <double, double> getAjustX = x => 20 + 0.9 * (x - xM[0]) * pWidth / x_span; Func <double, double> getAjustY = y => - 20 + pHeight - 0.9 * (y - yM[0]) * pHeight / y_span; //纵轴倒置 //==========================================================画图 坐标轴 //定义铅笔 Pen pen1 = new Pen(Color.Black, 1); //画坐标轴,带箭头 Pen pen2 = new Pen(Color.Black, 1); //画刻度 Pen pen3 = new Pen(Color.LightGray, 1); //画背景虚线 pen3.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; //定义铅笔的头部箭头 System.Drawing.Drawing2D.AdjustableArrowCap lineArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); pen1.CustomEndCap = lineArrow; //--------------------定义坐标轴刻度 //坐标轴刻度 - 先按照 10格 double x_kedu = Math.Ceiling(x_span / 10);//刻度 double y_kedu = Math.Ceiling(y_span / 10); double x_o = xM[0] + x_kedu * 0.5;//坐标轴所在位置 double y_o = yM[0] + y_kedu * 0.6; //--------------------画坐标轴 //定义坐标点-x轴 PointF px1 = new PointF(0, double2Float(getAjustY(y_o))); PointF px2 = new PointF(double2Float(getAjustX(xM[1])), double2Float(getAjustY(y_o))); //定义坐标点-y轴 PointF py1 = new PointF(double2Float(getAjustX(x_o)), double2Float(pHeight)); PointF py2 = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(yM[1]))); //画坐标轴 g.DrawLine(pen1, px1, px2); //x g.DrawLine(pen1, py1, py2); //y //--------------------画坐标轴刻度 double x_axis = xM[0]; double y_axis = yM[0]; int ke_height = 6; //刻度尺寸 int font_size = 8; Font font = new Font("微软雅黑", font_size); //刻度字体 Brush brush = new SolidBrush(Color.Black); //用笔刷定义刻度字体颜色 PointF kedu_point; // = new PointF();//刻度的坐标 //坐标标度如果太大,则用科学技术法表示 Func <double, string> num2String = d => Int64.Parse(d.ToString()).ToString("E2"); //保留4位有效数字 //x轴刻度 while (x_axis < xM[1]) { //刻度向右递增 x_axis += x_kedu; //定义刻度线的首尾点 PointF px_k1 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(y_o)) - ke_height); PointF px_k2 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(y_o))); //画刻度 g.DrawLine(pen2, px_k1, px_k2); //画背景虚线 PointF px_k3 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(yM[0]))); PointF px_k4 = new PointF(double2Float(getAjustX(x_axis)), double2Float(getAjustY(yM[1]))); g.DrawLine(pen3, px_k3, px_k4); //标上刻度 kedu_point = new PointF(double2Float(getAjustX(x_axis)) - font_size, double2Float(getAjustY(y_o))); g.DrawString(x_axis.ToString(), font, brush, kedu_point); if (x_axis > 1000) { g.DrawString(num2String(x_axis), font, brush, kedu_point); } else { g.DrawString(x_axis.ToString(), font, brush, kedu_point); } } //y轴刻度 while (y_axis < yM[1]) { //刻度向右递增 y_axis += y_kedu; //定义刻度线的首尾点 PointF py_k1 = new PointF(double2Float(getAjustX(x_o)) + ke_height, double2Float(getAjustY(y_axis))); PointF py_k2 = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(y_axis))); //画刻度 g.DrawLine(pen2, py_k1, py_k2); //画背景虚线 PointF py_k3 = new PointF(double2Float(getAjustX(xM[0])), double2Float(getAjustY(y_axis))); PointF py_k4 = new PointF(double2Float(getAjustX(xM[1])), double2Float(getAjustY(y_axis))); g.DrawLine(pen3, py_k3, py_k4); //标上刻度 int y_axis_len = y_axis.ToString().Length; //kedu_point = new PointF(double2Float(getAjustX(x_o)) - y_axis_len * font_size, double2Float(getAjustY(y_axis))); kedu_point = new PointF(double2Float(getAjustX(x_o)), double2Float(getAjustY(y_axis))); if (y_axis > 1000) { g.DrawString(num2String(y_axis), font, brush, kedu_point); } else { g.DrawString(y_axis.ToString(), font, brush, kedu_point);//num2String } } //==========================================================画标注 主标题和坐标注释 g.DrawString("线性拟合标准曲线", new Font("宋体", 10), new SolidBrush(Color.Black), new Point(Width / 4, 10)); //==========================================================画图 拟合曲线 //细分点数 int dot_num = 10; List <PointF> pointFList = new List <PointF>(); //计算拟合出来的点 double[] xp = new double[dot_num]; double[] yp = new double[dot_num]; for (int i = 0; i < dot_num; i++) { //生成点 xp[i] = xM[0] + i * x_span / dot_num; yp[i] = a0 + a1 * xp[i]; //针对当前画布调整 xp[i] = double2Float(getAjustX(xp[i])); yp[i] = double2Float(getAjustY(yp[i])); //记录曲线 pointFList.Add(new PointF(double2Float(xp[i]), double2Float(yp[i]))); } //画很多线 - 很多点连起来就是一条直线 myDraw.DrawLine(g, pointFList); //==========================================================画图 std原始点 //画std原始点 //myDraw.DrawPoints(g, xp, yp,1,true); PointF p = new PointF(); int dot_radius = 6;//空心点的大小 for (int i = 0; i < stdPoints.Count; i++) { p = stdPoints[i]; p.X = double2Float(getAjustX(p.X)); p.Y = double2Float(getAjustY(p.Y)); g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, dot_radius, dot_radius); } }
public override void Refresh() { if (myDiagram.DrawMailConnectors) { System.Drawing.Drawing2D.AdjustableArrowCap arrowCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); Pen pn; Pen pn2; Brush drawBrush = Brushes.LightCoral; if (IsSelected) { pn = new Pen(Color.Firebrick, 2); pn2 = new Pen(Color.Firebrick, 2); } else { pn = new Pen(Color.LightCoral, 3); pn2 = new Pen(myDiagram.BrushDrawingSurface, 3); } pn.CustomStartCap = arrowCap; pn2.CustomStartCap = arrowCap; Rectangle ConnectorBox = new Rectangle(); Point cntr = new Point((myPts[0].X + myPts[myPts.Length - 1].X) / 2 - 6, (myPts[0].Y + myPts[myPts.Length - 1].Y) / 2 - 6); if (myACD != null) { ConnectorBox = new Rectangle(cntr.X - 8, cntr.Y - 2, 38, 16); myDiagram.drawingSurface.DrawRectangle(myDiagram.PenSteelBlue, ConnectorBox); } OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(-2); myDiagram.drawingSurface.DrawLines(pn2, myPts); OffsetMyYPoints(1); myDiagram.drawingSurface.DrawLines(pn, myPts); if (myACD != null) { StringFormat sformat = new StringFormat(); sformat.Alignment = StringAlignment.Center; sformat.LineAlignment = StringAlignment.Center; myDiagram.drawingSurface.FillRectangle(myDiagram.BrushWhite, ConnectorBox); myDiagram.drawingSurface.DrawImage(Properties.Resources.mailConnectors, ConnectorBox.X + 2, ConnectorBox.Y + 1); myDiagram.drawingSurface.DrawString("RA", myDiagram.DrawFont, myDiagram.BrushBlack, ConnectorBox.X + 26, ConnectorBox.Y + 10, sformat); if (myACD.RowState == System.Data.DataRowState.Modified) { myDiagram.drawingSurface.DrawString("* [edited] *", myDiagram.SelectedFont, Brushes.Black, cntr.X + 8, cntr.Y - 8, sformat); } sformat.Dispose(); } pn.Dispose(); pn2.Dispose(); arrowCap.Dispose(); } }
private void DrawArrowFunct(Bitmap img) { Pen pen = new Pen(Color.Blue, 3); Graphics g = Graphics.FromImage(img); double length= 60; double angle1 = (Math.PI / -180.0) * (ArrowAngle + 90); // to radians, -180 to get ccw, +90 to start from up double angle2 = (Math.PI / -180.0) * (ArrowAngle - 90); // to radians, -180 to get ccw, -90 to draw from center away //Draw end g.DrawLine(pen, FrameCenterX, FrameCenterY, (int)(FrameCenterX + Math.Cos(angle2) * length), (int)(FrameCenterY + Math.Sin(angle2) * length)); // draw head System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 6); pen.CustomEndCap = bigArrow; g.DrawLine(pen, FrameCenterX, FrameCenterY, (int)(FrameCenterX + Math.Cos(angle1) * length), (int)(FrameCenterY + Math.Sin(angle1) * length)); pen.Dispose(); g.Dispose(); }
/// <summary> /// Draws the switching graph in a bitmap. /// </summary> /// <returns></returns> public Bitmap Draw() { Bitmap Result = new Bitmap(1000, 1000); Graphics G = Graphics.FromImage(Result); Pen TreeP = new Pen(new SolidBrush(Color.Red)); Pen CycleP = new Pen(new SolidBrush(Color.Blue)); double Angle = 2 * Math.PI / Nodes.Count; double Radius = 400; for (int i = 0; i < Nodes.Count; i++) { double CurrentAngle = Angle * i; double X = 500 + Radius * Math.Cos(CurrentAngle); double Y = 500 + Radius * Math.Sin(CurrentAngle); Pen P; if (Components[Nodes[i].Component].IsCycle) P = CycleP; else P = TreeP; G.DrawRectangle(P, (int)X, (int)Y, 20, 20); Nodes[i].X = (int)X; Nodes[i].Y = (int)Y; G.DrawString(Nodes[i].Post.ID.ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), (float)X, (float)Y); } System.Drawing.Drawing2D.AdjustableArrowCap bigArrow = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5); for (int i = 0; i < Nodes.Count; i++) { Pen P; if (Components[Nodes[i].Component].IsCycle) P = CycleP; else P = TreeP; P.CustomEndCap = bigArrow; foreach (Edge e in Nodes[i].Outgoing) { G.DrawLine(P, e.Start.X, e.Start.Y, e.End.X, e.End.Y); G.DrawString(e.Applicant.ID.ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), (float)(e.Start.X + e.End.X) / 2, (float)(e.Start.Y + e.End.Y) / 2); } } return Result; }