/// <summary> /// Builds a chart label with the specified properties. /// </summary> /// <param name="text"></param> /// <param name="location"></param> /// <param name="compass"></param> private void makeLabel(string text, Point location, LabelCompassEnum compass) { C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel(); lab.Style.Border.BorderStyle = BorderStyleEnum.Solid; lab.Text = text; lab.AttachMethod = AttachMethodEnum.Coordinate; lab.AttachMethodData.X = location.X; lab.AttachMethodData.Y = location.Y; lab.Style.HorizontalAlignment = AlignHorzEnum.Near; lab.Compass = compass; lab.Visible = true; }
private LabelCompassEnum getLabelCompassFromAngle(double angle) { LabelCompassEnum lce = LabelCompassEnum.East; if (angle >= -22.5 && angle < 22.5) { lce = LabelCompassEnum.East; } else if (angle >= 22.5 && angle < 67.5) { lce = LabelCompassEnum.SouthEast; } else if (angle >= 67.5 && angle < 112.5) { lce = LabelCompassEnum.South; } else if (angle >= 112.5 && angle < 157.5) { lce = LabelCompassEnum.SouthWest; } else if (angle >= 157.5 || angle <= -157.5) { lce = LabelCompassEnum.West; } else if (angle <= -112.5 && angle > -157.5) { lce = LabelCompassEnum.NorthWest; } else if (angle <= -67.5 && angle > -112.5) { lce = LabelCompassEnum.North; } else if (angle <= -22.5 && angle > -67.5) { lce = LabelCompassEnum.NorthEast; } return(lce); }
private void HighlightObject(object obj) { // do nothing if still same object if (obj != null) { if (obj.Equals(highlightedObject)) { return; } } // since they are different, clear the original // object if it's not null highlightedObject = null; if (highlightedObjectStyle != null) { highlightedObjectStyle.BackColor = objectBackColor; objectBackColor = Color.Empty; highlightedObjectStyle = null; } C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[labName]; if (lab != null) { c1Chart1.ChartLabels.LabelsCollection.Remove(lab); } if (obj == null) { UpdateFooter(); return; } // handle the changes for the new object highlighting string describe = null; Point atPoint = Point.Empty; LabelCompassEnum cp = LabelCompassEnum.NorthWest; if (obj is Legend) { Legend leg = (Legend)obj; describe = " This is the Legend! "; atPoint = leg.Location; highlightedObjectStyle = leg.Style; } else if (obj is Title) { Title t = (Title)obj; highlightedObjectStyle = t.Style; if (highlightedObjectStyle.Border.BorderStyle.Equals(BorderStyleEnum.None)) { describe = " This is the Footer! "; atPoint = t.Location; atPoint.X += t.Size.Width; cp = LabelCompassEnum.NorthEast; } else { describe = " This is the \nHeader! "; atPoint = t.Location; atPoint.X += t.Size.Width; atPoint.Y += t.Size.Height; cp = LabelCompassEnum.SouthEast; } } if (!atPoint.IsEmpty) { C1.Win.C1Chart.Label nl = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel(); nl.Compass = cp; nl.Name = labName; nl.Connected = true; nl.Offset = 10; nl.AttachMethod = AttachMethodEnum.Coordinate; nl.AttachMethodData.X = atPoint.X; nl.AttachMethodData.Y = atPoint.Y; nl.Style.BackColor = Color.RosyBrown; nl.Style.Border.BorderStyle = BorderStyleEnum.Solid; nl.Style.Border.Thickness = 2; nl.Style.Font = new Font(nl.Style.Font.Name, 10, FontStyle.Bold); nl.Style.HorizontalAlignment = AlignHorzEnum.Center; nl.Text = describe; nl.Visible = true; objectBackColor = highlightedObjectStyle.BackColor; highlightedObjectStyle.BackColor = Color.RosyBrown; highlightedObject = obj; } UpdateFooter(); }
private void picSelect_Paint(object sender, PaintEventArgs e) { PictureBox pic = sender as PictureBox; if (pic != null) { Graphics g = e.Graphics; Font f = this.Font; int fs = (int)(f.SizeInPoints * e.Graphics.DpiY / 72); Rectangle rect = Rectangle.Inflate(pic.DisplayRectangle, -(12 + fs), -(12 + fs)); Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); if (pic.Tag == null) { pic.Tag = rect; } double radiusi = rect.Width / 2; double radiuso = radiusi + 5; double radiuss = radiuso + 5 + fs / 2; string[] cps = new string[] { "E", "SE", "S", "SW", "W", "NW", "N", "NE" }; int inc = 360 / cps.Length; LabelCompassEnum lce = c1Chart1.ChartLabels[0].Compass; for (int s = 0; s < cps.Length; s++) { int i = s * inc; Brush brush = ((i & 1) == 0) ? Brushes.CornflowerBlue : Brushes.Cornsilk; if (radioCompass.Checked && lce == getLabelCompassFromAngle((i > 180) ? i - 360 : i)) { brush = Brushes.DarkRed; g.FillPie(brush, rect, i - inc / 2, inc); g.DrawPie(Pens.DarkBlue, rect, i - inc / 2, inc); } else { g.FillPie(brush, rect, i - inc / 2, inc); } double angle = i * Math.PI / 180; double cos = Math.Cos(angle); double sin = Math.Sin(angle); string str = radioCompass.Checked ? cps[s] : i.ToString(); SizeF sz = g.MeasureString(str, f); Point tick = new Point((int)(center.X + radiusi * cos), (int)(center.Y + radiusi * sin)); Point tickr = new Point((int)(center.X + radiuso * cos), (int)(center.Y + radiuso * sin)); Point sloc = new Point((int)(center.X + radiuss * cos - sz.Width / 2), (int)(center.Y + radiuss * sin - sz.Height / 2)); g.DrawLine(Pens.Black, tick, tickr); g.DrawString(str, this.Font, Brushes.Black, sloc); } if (radioRotation.Checked) { double angle = c1Chart1.ChartLabels[0].RotationOverride * Math.PI / 180; double cos = Math.Cos(angle); double sin = Math.Sin(angle); Point tick = new Point((int)(center.X + radiusi * cos), (int)(center.Y + radiusi * sin)); g.DrawLine(Pens.DarkRed, center, tick); } g.DrawEllipse(Pens.Black, rect); } }