LineAnnotation.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: Line annotation class.
  6. //
  7. using System;
  8. using System.ComponentModel;
  9. using System.Drawing;
  10. using System.Drawing.Design;
  11. using System.Drawing.Drawing2D;
  12. using FastReport.DataVisualization.Charting.Utilities;
  13. namespace FastReport.DataVisualization.Charting
  14. {
  15. /// <summary>
  16. /// <b>LineAnnotation</b> is a class that represents a line annotation.
  17. /// </summary>
  18. [
  19. SRDescription("DescriptionAttributeLineAnnotation_LineAnnotation"),
  20. ]
  21. public class LineAnnotation : Annotation
  22. {
  23. #region Fields
  24. // Indicates that an infinitive line should be drawn through 2 specified points.
  25. private bool _isInfinitive = false;
  26. // Line start/end caps
  27. private LineAnchorCapStyle _startCap = LineAnchorCapStyle.None;
  28. private LineAnchorCapStyle _endCap = LineAnchorCapStyle.None;
  29. #endregion
  30. #region Construction and Initialization
  31. /// <summary>
  32. /// Default public constructor.
  33. /// </summary>
  34. public LineAnnotation()
  35. : base()
  36. {
  37. this.anchorAlignment = ContentAlignment.TopLeft;
  38. }
  39. #endregion
  40. #region Properties
  41. #region Line Visual Attributes
  42. /// <summary>
  43. /// Gets or sets a flag that indicates if an infinitive line should be drawn.
  44. /// </summary>
  45. /// <value>
  46. /// <b>True</b> if a line should be drawn infinitively through 2 points provided, <b>false</b> otherwise.
  47. /// </value>
  48. [
  49. SRCategory("CategoryAttributeAppearance"),
  50. DefaultValue(false),
  51. SRDescription("DescriptionAttributeDrawInfinitive"),
  52. ]
  53. virtual public bool IsInfinitive
  54. {
  55. get
  56. {
  57. return _isInfinitive;
  58. }
  59. set
  60. {
  61. _isInfinitive = value;
  62. Invalidate();
  63. }
  64. }
  65. /// <summary>
  66. /// Gets or sets a cap style used at the start of an annotation line.
  67. /// <seealso cref="EndCap"/>
  68. /// </summary>
  69. /// <value>
  70. /// A <see cref="LineAnchorCapStyle"/> value, used for a cap style used at the start of an annotation line.
  71. /// </value>
  72. [
  73. SRCategory("CategoryAttributeAppearance"),
  74. DefaultValue(LineAnchorCapStyle.None),
  75. SRDescription("DescriptionAttributeStartCap3"),
  76. ]
  77. virtual public LineAnchorCapStyle StartCap
  78. {
  79. get
  80. {
  81. return _startCap;
  82. }
  83. set
  84. {
  85. _startCap = value;
  86. Invalidate();
  87. }
  88. }
  89. /// <summary>
  90. /// Gets or sets a cap style used at the end of an annotation line.
  91. /// <seealso cref="StartCap"/>
  92. /// </summary>
  93. /// <value>
  94. /// A <see cref="LineAnchorCapStyle"/> value, used for a cap style used at the end of an annotation line.
  95. /// </value>
  96. [
  97. SRCategory("CategoryAttributeAppearance"),
  98. DefaultValue(LineAnchorCapStyle.None),
  99. SRDescription("DescriptionAttributeStartCap3"),
  100. ]
  101. virtual public LineAnchorCapStyle EndCap
  102. {
  103. get
  104. {
  105. return _endCap;
  106. }
  107. set
  108. {
  109. _endCap = value;
  110. Invalidate();
  111. }
  112. }
  113. #endregion
  114. #region Non Applicable Annotation Appearance Attributes (set as Non-Browsable)
  115. /// <summary>
  116. /// Not applicable to this annotation type.
  117. /// </summary>
  118. /// <value>
  119. /// A <see cref="ContentAlignment"/> value.
  120. /// </value>
  121. [
  122. SRCategory("CategoryAttributeAppearance"),
  123. Browsable(false),
  124. DefaultValue(typeof(ContentAlignment), "MiddleCenter"),
  125. ]
  126. override public ContentAlignment Alignment
  127. {
  128. get
  129. {
  130. return base.Alignment;
  131. }
  132. set
  133. {
  134. base.Alignment = value;
  135. }
  136. }
  137. /// <summary>
  138. /// Gets or sets an annotation's text style.
  139. /// <seealso cref="Font"/>
  140. /// <seealso cref="ForeColor"/>
  141. /// </summary>
  142. /// <value>
  143. /// A <see cref="TextStyle"/> value used to draw an annotation's text.
  144. /// </value>
  145. [Browsable(false)]
  146. [EditorBrowsable(EditorBrowsableState.Never)]
  147. public override TextStyle TextStyle
  148. {
  149. get
  150. {
  151. return base.TextStyle;
  152. }
  153. set
  154. {
  155. base.TextStyle = value;
  156. }
  157. }
  158. /// <summary>
  159. /// Not applicable to this annotation type.
  160. /// <seealso cref="Font"/>
  161. /// </summary>
  162. /// <value>
  163. /// A <see cref="Color"/> value.
  164. /// </value>
  165. [
  166. SRCategory("CategoryAttributeAppearance"),
  167. Browsable(false),
  168. DefaultValue(typeof(Color), "Black"),
  169. SRDescription("DescriptionAttributeForeColor"),
  170. TypeConverter(typeof(ColorConverter)),
  171. #if DESIGNER
  172. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  173. #endif
  174. ]
  175. override public Color ForeColor
  176. {
  177. get
  178. {
  179. return base.ForeColor;
  180. }
  181. set
  182. {
  183. base.ForeColor = value;
  184. }
  185. }
  186. /// <summary>
  187. /// Not applicable to this annotation type.
  188. /// <seealso cref="ForeColor"/>
  189. /// </summary>
  190. /// <value>
  191. /// A <see cref="Font"/> object.
  192. /// </value>
  193. [
  194. SRCategory("CategoryAttributeAppearance"),
  195. Browsable(false),
  196. DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"),
  197. ]
  198. override public Font Font
  199. {
  200. get
  201. {
  202. return base.Font;
  203. }
  204. set
  205. {
  206. base.Font = value;
  207. }
  208. }
  209. /// <summary>
  210. /// Not applicable to this annotation type.
  211. /// </summary>
  212. [
  213. SRCategory("CategoryAttributeAppearance"),
  214. Browsable(false),
  215. DefaultValue(typeof(Color), ""),
  216. NotifyParentPropertyAttribute(true),
  217. TypeConverter(typeof(ColorConverter)),
  218. #if DESIGNER
  219. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  220. #endif
  221. ]
  222. override public Color BackColor
  223. {
  224. get
  225. {
  226. return base.BackColor;
  227. }
  228. set
  229. {
  230. base.BackColor = value;
  231. }
  232. }
  233. /// <summary>
  234. /// Not applicable to this annotation type.
  235. /// </summary>
  236. /// <value>
  237. /// A <see cref="ChartHatchStyle"/> value.
  238. /// </value>
  239. [
  240. SRCategory("CategoryAttributeAppearance"),
  241. Browsable(false),
  242. DefaultValue(ChartHatchStyle.None),
  243. NotifyParentPropertyAttribute(true),
  244. #if DESIGNER
  245. Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))
  246. #endif
  247. ]
  248. override public ChartHatchStyle BackHatchStyle
  249. {
  250. get
  251. {
  252. return base.BackHatchStyle;
  253. }
  254. set
  255. {
  256. base.BackHatchStyle = value;
  257. }
  258. }
  259. /// <summary>
  260. /// Not applicable to this annotation type.
  261. /// </summary>
  262. [
  263. SRCategory("CategoryAttributeAppearance"),
  264. Browsable(false),
  265. DefaultValue(GradientStyle.None),
  266. NotifyParentPropertyAttribute(true),
  267. #if DESIGNER
  268. Editor(typeof(GradientEditor), typeof(UITypeEditor))
  269. #endif
  270. ]
  271. override public GradientStyle BackGradientStyle
  272. {
  273. get
  274. {
  275. return base.BackGradientStyle;
  276. }
  277. set
  278. {
  279. base.BackGradientStyle = value;
  280. }
  281. }
  282. /// <summary>
  283. /// Not applicable to this annotation type.
  284. /// </summary>
  285. [
  286. SRCategory("CategoryAttributeAppearance"),
  287. Browsable(false),
  288. DefaultValue(typeof(Color), ""),
  289. NotifyParentPropertyAttribute(true),
  290. TypeConverter(typeof(ColorConverter)),
  291. #if DESIGNER
  292. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  293. #endif
  294. ]
  295. override public Color BackSecondaryColor
  296. {
  297. get
  298. {
  299. return base.BackSecondaryColor;
  300. }
  301. set
  302. {
  303. base.BackSecondaryColor = value;
  304. }
  305. }
  306. #endregion
  307. #region Position
  308. /// <summary>
  309. /// Gets or sets a flag that specifies whether the size of an annotation is always
  310. /// defined in relative chart coordinates.
  311. /// <seealso cref="Annotation.Width"/>
  312. /// <seealso cref="Annotation.Height"/>
  313. /// </summary>
  314. /// <value>
  315. /// <b>True</b> if an annotation's <see cref="Annotation.Width"/> and <see cref="Annotation.Height"/> are always
  316. /// in chart relative coordinates, <b>false</b> otherwise.
  317. /// </value>
  318. /// <remarks>
  319. /// An annotation's width and height may be set in relative chart or axes coordinates.
  320. /// By default, relative chart coordinates are used.
  321. /// <para>
  322. /// To use axes coordinates for size set the <b>IsSizeAlwaysRelative</b> property to
  323. /// <b>false</b> and either anchor the annotation to a data point or set the
  324. /// <see cref="Annotation.AxisX"/> or <see cref="Annotation.AxisY"/> properties.
  325. /// </para>
  326. /// </remarks>
  327. [
  328. SRCategory("CategoryAttributePosition"),
  329. DefaultValue(true),
  330. SRDescription("DescriptionAttributeSizeAlwaysRelative3"),
  331. ]
  332. override public bool IsSizeAlwaysRelative
  333. {
  334. get
  335. {
  336. return base.IsSizeAlwaysRelative;
  337. }
  338. set
  339. {
  340. base.IsSizeAlwaysRelative = value;
  341. }
  342. }
  343. #endregion // Position
  344. #region Anchor
  345. /// <summary>
  346. /// Gets or sets an annotation position's alignment to the anchor point.
  347. /// <seealso cref="Annotation.AnchorX"/>
  348. /// <seealso cref="Annotation.AnchorY"/>
  349. /// <seealso cref="Annotation.AnchorDataPoint"/>
  350. /// <seealso cref="Annotation.AnchorOffsetX"/>
  351. /// <seealso cref="Annotation.AnchorOffsetY"/>
  352. /// </summary>
  353. /// <value>
  354. /// A <see cref="ContentAlignment"/> value that represents the annotation's alignment to
  355. /// the anchor point.
  356. /// </value>
  357. /// <remarks>
  358. /// The annotation must be anchored using either <see cref="Annotation.AnchorDataPoint"/>, or the <see cref="Annotation.AnchorX"/>
  359. /// and <see cref="Annotation.AnchorY"/> properties. Its <see cref="Annotation.X"/> and <see cref="Annotation.Y"/>
  360. /// properties must be set to <b>Double.NaN</b>.
  361. /// </remarks>
  362. [
  363. SRCategory("CategoryAttributeAnchor"),
  364. Browsable(false),
  365. EditorBrowsableAttribute(EditorBrowsableState.Never),
  366. DefaultValue(typeof(ContentAlignment), "TopLeft"),
  367. SRDescription("DescriptionAttributeAnchorAlignment"),
  368. ]
  369. override public ContentAlignment AnchorAlignment
  370. {
  371. get
  372. {
  373. return base.AnchorAlignment;
  374. }
  375. set
  376. {
  377. base.AnchorAlignment = value;
  378. }
  379. }
  380. #endregion // Anchoring
  381. #region Other
  382. /// <summary>
  383. /// Gets or sets an annotation's type name.
  384. /// </summary>
  385. /// <remarks>
  386. /// This property is used to get the name of each annotation type
  387. /// (e.g. Line, Rectangle, Ellipse).
  388. /// <para>
  389. /// This property is for internal use and is hidden at design and run time.
  390. /// </para>
  391. /// </remarks>
  392. [
  393. SRCategory("CategoryAttributeMisc"),
  394. Bindable(true),
  395. Browsable(false),
  396. EditorBrowsableAttribute(EditorBrowsableState.Never),
  397. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  398. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  399. SRDescription("DescriptionAttributeAnnotationType"),
  400. ]
  401. public override string AnnotationType
  402. {
  403. get
  404. {
  405. return "Line";
  406. }
  407. }
  408. /// <summary>
  409. /// Gets or sets an annotation's selection points style.
  410. /// </summary>
  411. /// <value>
  412. /// A <see cref="SelectionPointsStyle"/> value that represents the annotation
  413. /// selection style.
  414. /// </value>
  415. /// <remarks>
  416. /// This property is for internal use and is hidden at design and run time.
  417. /// </remarks>
  418. [
  419. SRCategory("CategoryAttributeAppearance"),
  420. DefaultValue(SelectionPointsStyle.Rectangle),
  421. ParenthesizePropertyNameAttribute(true),
  422. Browsable(false),
  423. EditorBrowsableAttribute(EditorBrowsableState.Never),
  424. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  425. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  426. SRDescription("DescriptionAttributeSelectionPointsStyle"),
  427. ]
  428. override internal SelectionPointsStyle SelectionPointsStyle
  429. {
  430. get
  431. {
  432. return SelectionPointsStyle.TwoPoints;
  433. }
  434. }
  435. #endregion
  436. #endregion
  437. #region Methods
  438. /// <summary>
  439. /// Adjusts the two coordinates of the line.
  440. /// </summary>
  441. /// <param name="point1">First line coordinate.</param>
  442. /// <param name="point2">Second line coordinate.</param>
  443. /// <param name="selectionRect">Selection rectangle.</param>
  444. virtual internal void AdjustLineCoordinates(ref PointF point1, ref PointF point2, ref RectangleF selectionRect)
  445. {
  446. // Adjust line points to draw infinitive line
  447. if(IsInfinitive)
  448. {
  449. if(Math.Round(point1.X , 3) == Math.Round(point2.X, 3))
  450. {
  451. point1.Y = (point1.Y < point2.Y) ? 0f : 100f;
  452. point2.Y = (point1.Y < point2.Y) ? 100f : 0f;
  453. }
  454. else if(Math.Round(point1.Y , 3) == Math.Round(point2.Y, 3))
  455. {
  456. point1.X = (point1.X < point2.X) ? 0f : 100f;
  457. point2.X = (point1.X < point2.X) ? 100f : 0f;
  458. }
  459. else
  460. {
  461. // Calculate intersection point of the line with two bounaries Y = 0 and Y = 100
  462. PointF intersectionPoint1 = PointF.Empty;
  463. intersectionPoint1.Y = 0f;
  464. intersectionPoint1.X = (0f - point1.Y) *
  465. (point2.X - point1.X) /
  466. (point2.Y - point1.Y) +
  467. point1.X;
  468. PointF intersectionPoint2 = PointF.Empty;
  469. intersectionPoint2.Y = 100f;
  470. intersectionPoint2.X = (100f - point1.Y) *
  471. (point2.X - point1.X) /
  472. (point2.Y - point1.Y) +
  473. point1.X;
  474. // Select point closect to the intersection
  475. point1 = (point1.Y < point2.Y) ? intersectionPoint1 : intersectionPoint2;
  476. point2 = (point1.Y < point2.Y) ? intersectionPoint2 : intersectionPoint1;
  477. }
  478. }
  479. }
  480. /// <summary>
  481. /// Paints an annotation object on the specified graphics.
  482. /// </summary>
  483. /// <param name="graphics">
  484. /// A <see cref="ChartGraphics"/> object, used to paint an annotation object.
  485. /// </param>
  486. /// <param name="chart">
  487. /// Reference to the <see cref="Chart"/> owner control.
  488. /// </param>
  489. override internal void Paint(Chart chart, ChartGraphics graphics)
  490. {
  491. // Get annotation position in relative coordinates
  492. PointF firstPoint = PointF.Empty;
  493. PointF anchorPoint = PointF.Empty;
  494. SizeF size = SizeF.Empty;
  495. GetRelativePosition(out firstPoint, out size, out anchorPoint);
  496. PointF secondPoint = new PointF(firstPoint.X + size.Width, firstPoint.Y + size.Height);
  497. // Create selection rectangle
  498. RectangleF selectionRect = new RectangleF(firstPoint, new SizeF(secondPoint.X - firstPoint.X, secondPoint.Y - firstPoint.Y));
  499. // Adjust coordinates
  500. AdjustLineCoordinates(ref firstPoint, ref secondPoint, ref selectionRect);
  501. // Check if text position is valid
  502. if( float.IsNaN(firstPoint.X) ||
  503. float.IsNaN(firstPoint.Y) ||
  504. float.IsNaN(secondPoint.X) ||
  505. float.IsNaN(secondPoint.Y) )
  506. {
  507. return;
  508. }
  509. // Set line caps
  510. bool capChanged = false;
  511. LineCap oldStartCap = LineCap.Flat;
  512. LineCap oldEndCap = LineCap.Flat;
  513. if(this._startCap != LineAnchorCapStyle.None ||
  514. this._endCap != LineAnchorCapStyle.None)
  515. {
  516. capChanged = true;
  517. oldStartCap = graphics.Pen.StartCap;
  518. oldEndCap = graphics.Pen.EndCap;
  519. // Apply anchor cap settings
  520. if(this._startCap == LineAnchorCapStyle.Arrow)
  521. {
  522. // Adjust arrow size for small line width
  523. if(this.LineWidth < 4)
  524. {
  525. int adjustment = 3 - this.LineWidth;
  526. graphics.Pen.StartCap = LineCap.Custom;
  527. graphics.Pen.CustomStartCap = new AdjustableArrowCap(
  528. this.LineWidth + adjustment,
  529. this.LineWidth + adjustment,
  530. true);
  531. }
  532. else
  533. {
  534. graphics.Pen.StartCap = LineCap.ArrowAnchor;
  535. }
  536. }
  537. else if(this._startCap == LineAnchorCapStyle.Diamond)
  538. {
  539. graphics.Pen.StartCap = LineCap.DiamondAnchor;
  540. }
  541. else if(this._startCap == LineAnchorCapStyle.Round)
  542. {
  543. graphics.Pen.StartCap = LineCap.RoundAnchor;
  544. }
  545. else if(this._startCap == LineAnchorCapStyle.Square)
  546. {
  547. graphics.Pen.StartCap = LineCap.SquareAnchor;
  548. }
  549. if(this._endCap == LineAnchorCapStyle.Arrow)
  550. {
  551. // Adjust arrow size for small line width
  552. if(this.LineWidth < 4)
  553. {
  554. int adjustment = 3 - this.LineWidth;
  555. graphics.Pen.EndCap = LineCap.Custom;
  556. graphics.Pen.CustomEndCap = new AdjustableArrowCap(
  557. this.LineWidth + adjustment,
  558. this.LineWidth + adjustment,
  559. true);
  560. }
  561. else
  562. {
  563. graphics.Pen.EndCap = LineCap.ArrowAnchor;
  564. }
  565. }
  566. else if(this._endCap == LineAnchorCapStyle.Diamond)
  567. {
  568. graphics.Pen.EndCap = LineCap.DiamondAnchor;
  569. }
  570. else if(this._endCap == LineAnchorCapStyle.Round)
  571. {
  572. graphics.Pen.EndCap = LineCap.RoundAnchor;
  573. }
  574. else if(this._endCap == LineAnchorCapStyle.Square)
  575. {
  576. graphics.Pen.EndCap = LineCap.SquareAnchor;
  577. }
  578. }
  579. if(this.Common.ProcessModePaint)
  580. {
  581. // Draw line
  582. graphics.DrawLineRel(
  583. this.LineColor,
  584. this.LineWidth,
  585. this.LineDashStyle,
  586. firstPoint,
  587. secondPoint,
  588. this.ShadowColor,
  589. this.ShadowOffset);
  590. }
  591. if(this.Common.ProcessModeRegions)
  592. {
  593. // Create line graphics path
  594. using (GraphicsPath path = new GraphicsPath())
  595. {
  596. path.AddLine(
  597. graphics.GetAbsolutePoint(firstPoint),
  598. graphics.GetAbsolutePoint(secondPoint));
  599. using (Pen pen = (Pen)graphics.Pen.Clone())
  600. {
  601. // Increase pen size by 2 pixels
  602. pen.DashStyle = DashStyle.Solid;
  603. pen.Width += 2;
  604. try
  605. {
  606. path.Widen(pen);
  607. }
  608. catch (OutOfMemoryException)
  609. {
  610. // GraphicsPath.Widen incorrectly throws OutOfMemoryException
  611. // catching here and reacting by not widening
  612. }
  613. catch (ArgumentException)
  614. {
  615. }
  616. }
  617. // Add hot region
  618. this.Common.HotRegionsList.AddHotRegion(
  619. graphics,
  620. path,
  621. false,
  622. ReplaceKeywords(this.ToolTip),
  623. String.Empty,
  624. String.Empty,
  625. String.Empty,
  626. this,
  627. ChartElementType.Annotation);
  628. }
  629. }
  630. // Restore line caps
  631. if(capChanged)
  632. {
  633. graphics.Pen.StartCap = oldStartCap;
  634. graphics.Pen.EndCap = oldEndCap;
  635. }
  636. // Paint selection handles
  637. PaintSelectionHandles(graphics, selectionRect, null);
  638. }
  639. #endregion
  640. }
  641. /// <summary>
  642. /// <b>VerticalLineAnnotation</b> is a class that represents a vertical line annotation.
  643. /// </summary>
  644. [
  645. SRDescription("DescriptionAttributeVerticalLineAnnotation_VerticalLineAnnotation"),
  646. ]
  647. public class VerticalLineAnnotation : LineAnnotation
  648. {
  649. #region Construction and Initialization
  650. /// <summary>
  651. /// Default public constructor.
  652. /// </summary>
  653. public VerticalLineAnnotation()
  654. : base()
  655. {
  656. }
  657. #endregion
  658. #region Properties
  659. /// <summary>
  660. /// Gets or sets an annotation's type name.
  661. /// </summary>
  662. /// <remarks>
  663. /// This property is used to get the name of each annotation type
  664. /// (e.g. Line, Rectangle, Ellipse).
  665. /// <para>
  666. /// This property is for internal use and is hidden at design and run time.
  667. /// </para>
  668. /// </remarks>
  669. [
  670. SRCategory("CategoryAttributeMisc"),
  671. Bindable(true),
  672. Browsable(false),
  673. EditorBrowsableAttribute(EditorBrowsableState.Never),
  674. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  675. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  676. SRDescription("DescriptionAttributeAnnotationType"),
  677. ]
  678. public override string AnnotationType
  679. {
  680. get
  681. {
  682. return "VerticalLine";
  683. }
  684. }
  685. #endregion
  686. #region Methods
  687. /// <summary>
  688. /// Adjusts the two coordinates of the line.
  689. /// </summary>
  690. /// <param name="point1">First line coordinate.</param>
  691. /// <param name="point2">Second line coordinate.</param>
  692. /// <param name="selectionRect">Selection rectangle.</param>
  693. override internal void AdjustLineCoordinates(ref PointF point1, ref PointF point2, ref RectangleF selectionRect)
  694. {
  695. // Make line vertical
  696. point2.X = point1.X;
  697. selectionRect.Width = 0f;
  698. // Call base class
  699. base.AdjustLineCoordinates(ref point1, ref point2, ref selectionRect);
  700. }
  701. #region Content Size
  702. /// <summary>
  703. /// Gets text annotation content size based on the text and font.
  704. /// </summary>
  705. /// <returns>Annotation content position.</returns>
  706. override internal RectangleF GetContentPosition()
  707. {
  708. return new RectangleF(float.NaN, float.NaN, 0f, float.NaN);
  709. }
  710. #endregion // Content Size
  711. #endregion
  712. }
  713. /// <summary>
  714. /// <b>HorizontalLineAnnotation</b> is a class that represents a horizontal line annotation.
  715. /// </summary>
  716. [
  717. SRDescription("DescriptionAttributeHorizontalLineAnnotation_HorizontalLineAnnotation"),
  718. ]
  719. public class HorizontalLineAnnotation : LineAnnotation
  720. {
  721. #region Construction and Initialization
  722. /// <summary>
  723. /// Default public constructor.
  724. /// </summary>
  725. public HorizontalLineAnnotation()
  726. : base()
  727. {
  728. }
  729. #endregion
  730. #region Properties
  731. /// <summary>
  732. /// Gets or sets an annotation's type name.
  733. /// </summary>
  734. /// <remarks>
  735. /// This property is used to get the name of each annotation type
  736. /// (e.g. Line, Rectangle, Ellipse).
  737. /// <para>
  738. /// This property is for internal use and is hidden at design and run time.
  739. /// </para>
  740. /// </remarks>
  741. [
  742. SRCategory("CategoryAttributeMisc"),
  743. Bindable(true),
  744. Browsable(false),
  745. EditorBrowsableAttribute(EditorBrowsableState.Never),
  746. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  747. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  748. SRDescription("DescriptionAttributeAnnotationType"),
  749. ]
  750. public override string AnnotationType
  751. {
  752. get
  753. {
  754. return "HorizontalLine";
  755. }
  756. }
  757. #endregion
  758. #region Methods
  759. /// <summary>
  760. /// Adjusts the two coordinates of the line.
  761. /// </summary>
  762. /// <param name="point1">First line coordinate.</param>
  763. /// <param name="point2">Second line coordinate.</param>
  764. /// <param name="selectionRect">Selection rectangle.</param>
  765. override internal void AdjustLineCoordinates(ref PointF point1, ref PointF point2, ref RectangleF selectionRect)
  766. {
  767. // Make line horizontal
  768. point2.Y = point1.Y;
  769. selectionRect.Height = 0f;
  770. // Call base class
  771. base.AdjustLineCoordinates(ref point1, ref point2, ref selectionRect);
  772. }
  773. #region Content Size
  774. /// <summary>
  775. /// Gets text annotation content size based on the text and font.
  776. /// </summary>
  777. /// <returns>Annotation content position.</returns>
  778. override internal RectangleF GetContentPosition()
  779. {
  780. return new RectangleF(float.NaN, float.NaN, float.NaN, 0f);
  781. }
  782. #endregion // Content Size
  783. #endregion
  784. }
  785. }