AxisScrollBar.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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: AxisScrollBar class represent axis scroolbar. There
  6. // is a big difference how this UI functionality
  7. // implemented for Windows Forms and ASP.NET. For
  8. // Windows Forms a custom drawn scrollbar control is
  9. // drawn in the chart which reacts to the mouse input and
  10. // changes current axis data scaleView.
  11. //
  12. using System;
  13. using System.Windows.Forms;
  14. using System.ComponentModel;
  15. using System.Diagnostics.CodeAnalysis;
  16. using System.Drawing;
  17. using System.Drawing.Design;
  18. using System.Drawing.Drawing2D;
  19. using FastReport.DataVisualization.Charting.Utilities;
  20. namespace FastReport.DataVisualization.Charting
  21. {
  22. #region Scroll bar enumerations
  23. /// <summary>
  24. /// An enumeration of scrollbar button types.
  25. /// </summary>
  26. public enum ScrollBarButtonType
  27. {
  28. /// <summary>
  29. /// Thumb tracker button.
  30. /// </summary>
  31. ThumbTracker,
  32. /// <summary>
  33. /// Scroll by substracting small distance.
  34. /// </summary>
  35. SmallDecrement,
  36. /// <summary>
  37. /// Scroll by adding small distance.
  38. /// </summary>
  39. SmallIncrement,
  40. /// <summary>
  41. /// Scroll by substracting large distance.
  42. /// </summary>
  43. LargeDecrement,
  44. /// <summary>
  45. /// Scroll by adding large distance.
  46. /// </summary>
  47. LargeIncrement,
  48. /// <summary>
  49. /// Zoom reset button.
  50. /// </summary>
  51. ZoomReset
  52. }
  53. /// <summary>
  54. /// An enumeration of scrollbar button style flags.
  55. /// </summary>
  56. [Flags]
  57. public enum ScrollBarButtonStyles
  58. {
  59. /// <summary>
  60. /// No buttons are shown.
  61. /// </summary>
  62. None = 0,
  63. /// <summary>
  64. /// Small increment or decrement buttons are shown.
  65. /// </summary>
  66. SmallScroll = 1,
  67. /// <summary>
  68. /// Reset zoom buttons are shown.
  69. /// </summary>
  70. ResetZoom = 2,
  71. /// <summary>
  72. /// All buttons are shown.
  73. /// </summary>
  74. All = SmallScroll | ResetZoom
  75. }
  76. #endregion
  77. /// <summary>
  78. /// AxisScrollBar class represents the axis scrollbar. It is exposed as the
  79. /// ScrollBar property of the Axis class. It contains scrollbar appearance
  80. /// properties and drawing methods.
  81. /// </summary>
  82. public class AxisScrollBar : IDisposable
  83. {
  84. #region Scroll bar fields
  85. // Reference to the axis data scaleView class
  86. internal Axis axis = null;
  87. // Indicates that scollbra will be drawn
  88. private bool _enabled = true;
  89. // Axis data scaleView scroll bar style
  90. private ScrollBarButtonStyles _scrollBarButtonStyle = ScrollBarButtonStyles.All;
  91. // Axis data scaleView scroll bar size
  92. private double _scrollBarSize = 14.0;
  93. // Index of the pressed butoon in the scroll bar
  94. private int _pressedButtonType = int.MaxValue;
  95. // Axis data scaleView scroll bar buttons color
  96. private Color _buttonColor = Color.Empty;
  97. // Axis data scaleView scroll bar back color
  98. private Color _backColor = Color.Empty;
  99. // Axis data scaleView scroll bar lines color
  100. private Color _lineColor = Color.Empty;
  101. // Current scroll bar drawing colors
  102. private Color _buttonCurrentColor = Color.Empty;
  103. private Color _backCurrentColor = Color.Empty;
  104. private Color _lineCurrentColor = Color.Empty;
  105. // Last mouse click mouse and scaleView position
  106. private PointF _lastClickMousePosition = PointF.Empty;
  107. private double _lastClickViewPosition = double.NaN;
  108. // Timer used to scroll the data while selecting
  109. private System.Windows.Forms.Timer _scrollTimer = new System.Windows.Forms.Timer();
  110. // Scroll size and direction when AutoScroll is set
  111. private MouseEventArgs _mouseArguments = null;
  112. // Position of the scrollbar (true - edge of PlotArea, false - edge of chart area)
  113. private bool _isPositionedInside = true;
  114. #endregion
  115. #region Scroll bar constructors and initialization
  116. /// <summary>
  117. /// AxisScrollBar constructor.
  118. /// </summary>
  119. public AxisScrollBar()
  120. {
  121. }
  122. /// <summary>
  123. /// Axis scroll bar constructor.
  124. /// </summary>
  125. /// <param name="axis">Reference to the axis class.</param>
  126. internal AxisScrollBar(Axis axis)
  127. {
  128. // Save reference to the axis data scaleView
  129. this.axis = axis;
  130. }
  131. /// <summary>
  132. /// Initialize axis scroll bar class.
  133. /// </summary>
  134. internal void Initialize()
  135. {
  136. }
  137. #endregion
  138. #region Scroll bar properties
  139. /// <summary>
  140. /// Gets or sets a flag which indicates whether scroll bar is positioned inside or outside of chart area.
  141. /// </summary>
  142. [
  143. SRCategory("CategoryAttributeAxisView"),
  144. Bindable(true),
  145. DefaultValue(true),
  146. SRDescription("DescriptionAttributeAxisScrollBar_PositionInside")
  147. ]
  148. public bool IsPositionedInside
  149. {
  150. get
  151. {
  152. return _isPositionedInside;
  153. }
  154. set
  155. {
  156. if(_isPositionedInside != value)
  157. {
  158. _isPositionedInside = value;
  159. if(axis != null)
  160. {
  161. axis.ChartArea.Invalidate();
  162. axis.CallOnModifing();
  163. }
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// Gets or sets a flag which indicates whether the scroll bar is enabled.
  169. /// </summary>
  170. [
  171. SRCategory("CategoryAttributeAxisView"),
  172. Bindable(true),
  173. DefaultValue(true),
  174. SRDescription("DescriptionAttributeAxisScrollBar_Enabled")
  175. ]
  176. public bool Enabled
  177. {
  178. get
  179. {
  180. return _enabled;
  181. }
  182. set
  183. {
  184. if(_enabled != value)
  185. {
  186. _enabled = value;
  187. if(axis != null)
  188. {
  189. axis.ChartArea.Invalidate();
  190. axis.CallOnModifing();
  191. }
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// Gets the ChartArea that contains this scrollbar.
  197. /// </summary>
  198. [
  199. Browsable(false),
  200. Bindable(false),
  201. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  202. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  203. ]
  204. public ChartArea ChartArea
  205. {
  206. get
  207. {
  208. return this.axis.ChartArea;
  209. }
  210. }
  211. /// <summary>
  212. /// Gets the Axis that contains this scrollbar.
  213. /// </summary>
  214. [
  215. Browsable(false),
  216. Bindable(false),
  217. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  218. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  219. ]
  220. public Axis Axis
  221. {
  222. get
  223. {
  224. return this.axis;
  225. }
  226. }
  227. /// <summary>
  228. /// Gets or sets the style of the scrollbar button.
  229. /// </summary>
  230. [
  231. SRCategory("CategoryAttributeAxisView"),
  232. Bindable(true),
  233. DefaultValue(ScrollBarButtonStyles.All),
  234. SRDescription("DescriptionAttributeAxisScrollBar_Buttons"),
  235. #if DESIGNER
  236. Editor(typeof(FlagsEnumUITypeEditor), typeof(UITypeEditor))
  237. #endif
  238. ]
  239. public ScrollBarButtonStyles ButtonStyle
  240. {
  241. get
  242. {
  243. return _scrollBarButtonStyle;
  244. }
  245. set
  246. {
  247. if(_scrollBarButtonStyle != value)
  248. {
  249. _scrollBarButtonStyle = value;
  250. if(axis != null)
  251. {
  252. axis.ChartArea.Invalidate();
  253. axis.CallOnModifing();
  254. }
  255. }
  256. }
  257. }
  258. /// <summary>
  259. /// Gets or sets the size of the scrollbar.
  260. /// </summary>
  261. [
  262. SRCategory("CategoryAttributeAxisView"),
  263. Bindable(true),
  264. DefaultValue(14.0),
  265. SRDescription("DescriptionAttributeAxisScrollBar_Size"),
  266. ]
  267. public double Size
  268. {
  269. get
  270. {
  271. return _scrollBarSize;
  272. }
  273. set
  274. {
  275. if(_scrollBarSize != value)
  276. {
  277. // Check values range
  278. if(value < 5.0 || value > 20.0)
  279. {
  280. throw (new ArgumentOutOfRangeException("value", SR.ExceptionScrollBarSizeInvalid));
  281. }
  282. _scrollBarSize = value;
  283. if(axis != null)
  284. {
  285. axis.ChartArea.Invalidate();
  286. axis.CallOnModifing();
  287. }
  288. }
  289. }
  290. }
  291. /// <summary>
  292. /// Gets or sets the button color of the scrollbar.
  293. /// </summary>
  294. [
  295. SRCategory("CategoryAttributeAxisView"),
  296. Bindable(true),
  297. DefaultValue(typeof(Color), ""),
  298. SRDescription("DescriptionAttributeAxisScrollBar_ButtonColor"),
  299. TypeConverter(typeof(ColorConverter)),
  300. #if DESIGNER
  301. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  302. #endif
  303. ]
  304. public Color ButtonColor
  305. {
  306. get
  307. {
  308. return _buttonColor;
  309. }
  310. set
  311. {
  312. if(_buttonColor != value)
  313. {
  314. _buttonColor = value;
  315. if(axis != null)
  316. {
  317. axis.ChartArea.Invalidate();
  318. axis.CallOnModifing();
  319. }
  320. }
  321. }
  322. }
  323. /// <summary>
  324. /// Gets or sets the line color of the scrollbar.
  325. /// </summary>
  326. [
  327. SRCategory("CategoryAttributeAxisView"),
  328. Bindable(true),
  329. DefaultValue(typeof(Color), ""),
  330. SRDescription("DescriptionAttributeLineColor"),
  331. TypeConverter(typeof(ColorConverter)),
  332. #if DESIGNER
  333. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  334. #endif
  335. ]
  336. public Color LineColor
  337. {
  338. get
  339. {
  340. return _lineColor;
  341. }
  342. set
  343. {
  344. if(_lineColor != value)
  345. {
  346. _lineColor = value;
  347. if(axis != null)
  348. {
  349. axis.ChartArea.Invalidate();
  350. axis.CallOnModifing();
  351. }
  352. }
  353. }
  354. }
  355. /// <summary>
  356. /// Gets or sets the background color of the scrollbar.
  357. /// </summary>
  358. [
  359. SRCategory("CategoryAttributeAxisView"),
  360. Bindable(true),
  361. DefaultValue(typeof(Color), ""),
  362. SRDescription("DescriptionAttributeBackColor"),
  363. TypeConverter(typeof(ColorConverter)),
  364. #if DESIGNER
  365. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  366. #endif
  367. ]
  368. public Color BackColor
  369. {
  370. get
  371. {
  372. return _backColor;
  373. }
  374. set
  375. {
  376. if(_backColor != value)
  377. {
  378. _backColor = value;
  379. if(axis != null)
  380. {
  381. axis.ChartArea.Invalidate();
  382. axis.CallOnModifing();
  383. }
  384. }
  385. }
  386. }
  387. #endregion
  388. #region Scroll bar public methods
  389. /// <summary>
  390. /// This method returns true if the scrollbar is visible.
  391. /// </summary>
  392. [Browsable(false)]
  393. [Utilities.SerializationVisibility(Utilities.SerializationVisibility.Hidden)]
  394. public bool IsVisible
  395. {
  396. get
  397. {
  398. // Check scroll bar enabled flag
  399. if (!this.Enabled)
  400. {
  401. return false;
  402. }
  403. // Do not show scroll bars while printing
  404. if (this.axis == null ||
  405. this.axis.ChartArea == null ||
  406. this.axis.ChartArea.Common == null ||
  407. this.axis.ChartArea.Common.ChartPicture == null ||
  408. this.axis.ChartArea.Common.ChartPicture.isPrinting)
  409. {
  410. return false;
  411. }
  412. #if SUBAXES
  413. // Scrollbar is not supported on the sub axis
  414. if(this.axis.IsSubAxis)
  415. {
  416. return false;
  417. }
  418. #endif // SUBAXES
  419. // Check if data scaleView size in percentage is less than 100%
  420. return (GetDataViewPercentage() < 100.0) ? true : false;
  421. }
  422. }
  423. #endregion
  424. #region Scroll bar painting methods
  425. /// <summary>
  426. /// Draws axis scroll bar.
  427. /// </summary>
  428. /// <param name="graph">Reference to the Chart Graphics object.</param>
  429. internal void Paint( ChartGraphics graph )
  430. {
  431. // Scroll bar border width
  432. int borderWidth = 1;
  433. // Scroll bar should not be visible
  434. if(!this.IsVisible)
  435. {
  436. return;
  437. }
  438. #if SUBAXES
  439. // Scrollbar not supported on sub axis
  440. if( this.axis != null && this.axis.IsSubAxis)
  441. {
  442. return;
  443. }
  444. #endif //SUBAXES
  445. // Set current scroll bar colors
  446. _buttonCurrentColor = this._buttonColor;
  447. _backCurrentColor = this._backColor;
  448. _lineCurrentColor = this._lineColor;
  449. // Make sure the current colors are not empty
  450. if(_buttonCurrentColor == Color.Empty)
  451. {
  452. _buttonCurrentColor = this.axis.ChartArea.BackColor;
  453. if(_buttonCurrentColor == Color.Empty)
  454. {
  455. _buttonCurrentColor = Color.DarkGray;
  456. }
  457. }
  458. if(_backCurrentColor == Color.Empty)
  459. {
  460. _backCurrentColor = this.axis.ChartArea.BackColor;
  461. if(_backCurrentColor == Color.Empty)
  462. {
  463. _backCurrentColor = Color.LightGray;
  464. }
  465. }
  466. if(_lineCurrentColor == Color.Empty)
  467. {
  468. _lineCurrentColor = this.axis.LineColor;
  469. if(_lineCurrentColor == Color.Empty)
  470. {
  471. _lineCurrentColor = Color.Black;
  472. }
  473. }
  474. // Get scroll bar rectangle
  475. RectangleF scrollBarRect = this.GetScrollBarRect();
  476. // Fill scroll bar background
  477. graph.FillRectangleRel(
  478. scrollBarRect,
  479. _backCurrentColor,
  480. ChartHatchStyle.None,
  481. "",
  482. ChartImageWrapMode.Tile,
  483. Color.Empty,
  484. ChartImageAlignmentStyle.Center,
  485. GradientStyle.None,
  486. Color.Empty,
  487. _lineCurrentColor,
  488. borderWidth,
  489. ChartDashStyle.Solid,
  490. Color.Empty,
  491. 0,
  492. PenAlignment.Outset );
  493. // Fill rectangle between to neighbour scroll bars
  494. PaintScrollBarConnectionRect(graph, scrollBarRect, borderWidth);
  495. // Get scroll bar client rectangle
  496. SizeF borderRelativeSize = new SizeF(borderWidth, borderWidth);
  497. borderRelativeSize = graph.GetRelativeSize(borderRelativeSize);
  498. RectangleF scrollBarClientRect = new RectangleF(scrollBarRect.Location, scrollBarRect.Size);
  499. scrollBarClientRect.Inflate(-borderRelativeSize.Width, -borderRelativeSize.Height);
  500. // Draw all button types
  501. foreach (ScrollBarButtonType buttonType in Enum.GetValues(typeof(ScrollBarButtonType)))
  502. {
  503. // Get button rectangle
  504. RectangleF buttonRect = this.GetScrollBarButtonRect(scrollBarClientRect, (ScrollBarButtonType)buttonType);
  505. // Paint button
  506. if(!buttonRect.IsEmpty)
  507. {
  508. PaintScrollBar3DButton(
  509. graph,
  510. buttonRect,
  511. ((ScrollBarButtonType)this._pressedButtonType) == (ScrollBarButtonType)buttonType,
  512. (ScrollBarButtonType)buttonType);
  513. }
  514. }
  515. if( this.ChartArea.Common.ProcessModeRegions )
  516. {
  517. SetHotRegionElement( this.ChartArea.Common );
  518. }
  519. }
  520. /// <summary>
  521. /// Fills a connection rectangle between two scoll bars.
  522. /// </summary>
  523. /// <param name="graph">Chart graphics.</param>
  524. /// <param name="scrollBarRect">Scroll bar position.</param>
  525. /// <param name="borderWidth">Border width.</param>
  526. private void PaintScrollBarConnectionRect(
  527. ChartGraphics graph,
  528. RectangleF scrollBarRect,
  529. int borderWidth)
  530. {
  531. // Do not draw anything if scroll bar is vertical
  532. if(this.axis.AxisPosition == AxisPosition.Left ||
  533. this.axis.AxisPosition == AxisPosition.Right)
  534. {
  535. return;
  536. }
  537. // Check if scoll bar is shown on the left/right sides of
  538. // the plotting area and get their sizes in relative coordinates
  539. float leftSize = 0f;
  540. float rightSize = 0f;
  541. foreach(Axis a in this.axis.ChartArea.Axes)
  542. {
  543. if(a.AxisPosition == AxisPosition.Left && a.ScrollBar.IsVisible && a.ScrollBar.IsPositionedInside == this.axis.ScrollBar.IsPositionedInside)
  544. {
  545. leftSize = (float)a.ScrollBar.GetScrollBarRelativeSize();
  546. }
  547. if(a.AxisPosition == AxisPosition.Right && a.ScrollBar.IsVisible && a.ScrollBar.IsPositionedInside == this.axis.ScrollBar.IsPositionedInside)
  548. {
  549. rightSize = (float)a.ScrollBar.GetScrollBarRelativeSize();
  550. }
  551. }
  552. // Prepare generic rectangle coordinates
  553. RectangleF connectorRect = new RectangleF(scrollBarRect.Location, scrollBarRect.Size);
  554. // Prepare coordinates and fill area to the left
  555. if(leftSize > 0f)
  556. {
  557. connectorRect.X = scrollBarRect.X - leftSize;
  558. connectorRect.Width = leftSize;
  559. // Fill background
  560. graph.FillRectangleRel(
  561. connectorRect,
  562. _backCurrentColor,
  563. ChartHatchStyle.None,
  564. "",
  565. ChartImageWrapMode.Tile,
  566. Color.Empty,
  567. ChartImageAlignmentStyle.Center,
  568. GradientStyle.None,
  569. Color.Empty,
  570. _lineCurrentColor,
  571. borderWidth,
  572. ChartDashStyle.Solid,
  573. Color.Empty,
  574. 0,
  575. PenAlignment.Outset );
  576. }
  577. // Prepare coordinates and fill area to the right
  578. if(rightSize > 0f)
  579. {
  580. connectorRect.X = scrollBarRect.Right;
  581. connectorRect.Width = rightSize;
  582. // Fill background
  583. graph.FillRectangleRel(
  584. connectorRect,
  585. _backCurrentColor,
  586. ChartHatchStyle.None,
  587. "",
  588. ChartImageWrapMode.Tile,
  589. Color.Empty,
  590. ChartImageAlignmentStyle.Center,
  591. GradientStyle.None,
  592. Color.Empty,
  593. _lineCurrentColor,
  594. borderWidth,
  595. ChartDashStyle.Solid,
  596. Color.Empty,
  597. 0,
  598. PenAlignment.Outset );
  599. }
  600. }
  601. /// <summary>
  602. /// Draws 3D button in the scroll bar
  603. /// </summary>
  604. /// <param name="graph">Chart graphics.</param>
  605. /// <param name="buttonRect">Button position.</param>
  606. /// <param name="pressedState">Indicates that button is pressed.</param>
  607. /// <param name="buttonType">Button type to draw.</param>
  608. internal void PaintScrollBar3DButton(
  609. ChartGraphics graph,
  610. RectangleF buttonRect,
  611. bool pressedState,
  612. ScrollBarButtonType buttonType)
  613. {
  614. // Page Up/Down buttons do not require drawing
  615. if(buttonType == ScrollBarButtonType.LargeIncrement || buttonType == ScrollBarButtonType.LargeDecrement)
  616. {
  617. return;
  618. }
  619. // Get 3 levels of colors for button drawing
  620. Color darkerColor = ChartGraphics.GetGradientColor(_buttonCurrentColor, Color.Black, 0.5);
  621. Color darkestColor = ChartGraphics.GetGradientColor(_buttonCurrentColor, Color.Black, 0.8);
  622. Color lighterColor = ChartGraphics.GetGradientColor(_buttonCurrentColor, Color.White, 0.5);
  623. // Fill button rectangle background
  624. graph.FillRectangleRel(
  625. buttonRect,
  626. _buttonCurrentColor,
  627. ChartHatchStyle.None,
  628. "",
  629. ChartImageWrapMode.Tile,
  630. Color.Empty,
  631. ChartImageAlignmentStyle.Center,
  632. GradientStyle.None,
  633. Color.Empty,
  634. darkerColor,
  635. (pressedState) ? 1 : 0,
  636. ChartDashStyle.Solid,
  637. Color.Empty,
  638. 0,
  639. PenAlignment.Outset );
  640. // Check if 2 or 1 pixel border will be drawn (if size too small)
  641. bool singlePixelBorder = this.Size <= 12;
  642. // Draw 3D effect around the button when not pressed
  643. if(!pressedState)
  644. {
  645. // Get relative size of 1 pixel
  646. SizeF pixelRelativeSize = new SizeF(1, 1);
  647. pixelRelativeSize = graph.GetRelativeSize(pixelRelativeSize);
  648. // Draw top/left border with button color
  649. graph.DrawLineRel(
  650. (singlePixelBorder) ? lighterColor : _buttonCurrentColor, 1, ChartDashStyle.Solid,
  651. new PointF(buttonRect.X, buttonRect.Bottom),
  652. new PointF(buttonRect.X, buttonRect.Top));
  653. graph.DrawLineRel(
  654. (singlePixelBorder) ? lighterColor : _buttonCurrentColor, 1, ChartDashStyle.Solid,
  655. new PointF(buttonRect.Left, buttonRect.Y),
  656. new PointF(buttonRect.Right, buttonRect.Y));
  657. // Draw right/bottom border with the darkest color
  658. graph.DrawLineRel(
  659. (singlePixelBorder) ? darkerColor : darkestColor, 1, ChartDashStyle.Solid,
  660. new PointF(buttonRect.Right, buttonRect.Bottom),
  661. new PointF(buttonRect.Right, buttonRect.Top));
  662. graph.DrawLineRel(
  663. (singlePixelBorder) ? darkerColor : darkestColor, 1, ChartDashStyle.Solid,
  664. new PointF(buttonRect.Left, buttonRect.Bottom),
  665. new PointF(buttonRect.Right, buttonRect.Bottom));
  666. if(!singlePixelBorder)
  667. {
  668. // Draw right/bottom border (offset 1) with the dark color
  669. graph.DrawLineRel(
  670. darkerColor, 1, ChartDashStyle.Solid,
  671. new PointF(buttonRect.Right-pixelRelativeSize.Width, buttonRect.Bottom-pixelRelativeSize.Height),
  672. new PointF(buttonRect.Right-pixelRelativeSize.Width, buttonRect.Top+pixelRelativeSize.Height));
  673. graph.DrawLineRel(
  674. darkerColor, 1, ChartDashStyle.Solid,
  675. new PointF(buttonRect.Left+pixelRelativeSize.Width, buttonRect.Bottom-pixelRelativeSize.Height),
  676. new PointF(buttonRect.Right-pixelRelativeSize.Width, buttonRect.Bottom-pixelRelativeSize.Height));
  677. // Draw top/left border (offset 1) with lighter color
  678. graph.DrawLineRel(
  679. lighterColor, 1, ChartDashStyle.Solid,
  680. new PointF(buttonRect.X+pixelRelativeSize.Width, buttonRect.Bottom-pixelRelativeSize.Height),
  681. new PointF(buttonRect.X+pixelRelativeSize.Width, buttonRect.Top+pixelRelativeSize.Height));
  682. graph.DrawLineRel(
  683. lighterColor, 1, ChartDashStyle.Solid,
  684. new PointF(buttonRect.Left+pixelRelativeSize.Width, buttonRect.Y+pixelRelativeSize.Height),
  685. new PointF(buttonRect.Right-pixelRelativeSize.Width, buttonRect.Y+pixelRelativeSize.Height));
  686. }
  687. }
  688. // Check axis orientation
  689. bool verticalAxis = (this.axis.AxisPosition == AxisPosition.Left ||
  690. this.axis.AxisPosition == AxisPosition.Right) ? true : false;
  691. // Set graphics transformation for button pressed mode
  692. float pressedShifting = (singlePixelBorder) ? 0.5f : 1f;
  693. if(pressedState)
  694. {
  695. graph.TranslateTransform(pressedShifting, pressedShifting);
  696. }
  697. // Draw button image
  698. RectangleF buttonAbsRect = graph.GetAbsoluteRectangle(buttonRect);
  699. float imageOffset = (singlePixelBorder) ? 2 : 3;
  700. switch(buttonType)
  701. {
  702. case(ScrollBarButtonType.SmallDecrement):
  703. {
  704. // Calculate triangal points position
  705. PointF[] points = new PointF[3];
  706. if(verticalAxis)
  707. {
  708. points[0].X = buttonAbsRect.X + imageOffset;
  709. points[0].Y = buttonAbsRect.Y + (imageOffset + 1f);
  710. points[1].X = buttonAbsRect.X + buttonAbsRect.Width/2f;
  711. points[1].Y = buttonAbsRect.Bottom - imageOffset;
  712. points[2].X = buttonAbsRect.Right - imageOffset;
  713. points[2].Y = buttonAbsRect.Y + (imageOffset + 1f);
  714. }
  715. else
  716. {
  717. points[0].X = buttonAbsRect.X + imageOffset;
  718. points[0].Y = buttonAbsRect.Y + buttonAbsRect.Height/2f;
  719. points[1].X = buttonAbsRect.Right - (imageOffset + 1f);
  720. points[1].Y = buttonAbsRect.Y + imageOffset;
  721. points[2].X = buttonAbsRect.Right - (imageOffset + 1f);
  722. points[2].Y = buttonAbsRect.Bottom - imageOffset;
  723. }
  724. using (Brush brush = new SolidBrush(this._lineCurrentColor))
  725. {
  726. graph.FillPolygon(brush, points);
  727. }
  728. break;
  729. }
  730. case(ScrollBarButtonType.SmallIncrement):
  731. {
  732. // Calculate triangal points position
  733. PointF[] points = new PointF[3];
  734. if(verticalAxis)
  735. {
  736. points[0].X = buttonAbsRect.X + imageOffset;
  737. points[0].Y = buttonAbsRect.Bottom - (imageOffset + 1f);
  738. points[1].X = buttonAbsRect.X + buttonAbsRect.Width/2f;
  739. points[1].Y = buttonAbsRect.Y + imageOffset;
  740. points[2].X = buttonAbsRect.Right - imageOffset;
  741. points[2].Y = buttonAbsRect.Bottom - (imageOffset + 1f);
  742. }
  743. else
  744. {
  745. points[0].X = buttonAbsRect.Right - imageOffset;
  746. points[0].Y = buttonAbsRect.Y + buttonAbsRect.Height/2f;
  747. points[1].X = buttonAbsRect.X + (imageOffset + 1f);
  748. points[1].Y = buttonAbsRect.Y + imageOffset;
  749. points[2].X = buttonAbsRect.X + (imageOffset + 1f);
  750. points[2].Y = buttonAbsRect.Bottom - imageOffset;
  751. }
  752. using (Brush brush = new SolidBrush(this._lineCurrentColor))
  753. {
  754. graph.FillPolygon(brush, points);
  755. }
  756. break;
  757. }
  758. case(ScrollBarButtonType.ZoomReset):
  759. {
  760. // Draw circule with a minus sign
  761. using (Pen pen = new Pen(this._lineCurrentColor, 1))
  762. {
  763. graph.DrawEllipse(pen, buttonAbsRect.X + imageOffset - 0.5f, buttonAbsRect.Y + imageOffset - 0.5f, buttonAbsRect.Width - 2f * imageOffset, buttonAbsRect.Height - 2f * imageOffset);
  764. graph.DrawLine(pen, buttonAbsRect.X + imageOffset + 1.5f, buttonAbsRect.Y + buttonAbsRect.Height / 2f - 0.5f, buttonAbsRect.Right - imageOffset - 2.5f, buttonAbsRect.Y + buttonAbsRect.Height / 2f - 0.5f);
  765. }
  766. break;
  767. }
  768. }
  769. // Reset graphics transformation for button pressed mode
  770. if(pressedState)
  771. {
  772. graph.TranslateTransform(-pressedShifting, -pressedShifting);
  773. }
  774. }
  775. #endregion
  776. #region Mouse events handling for the Scroll Bar
  777. /// <summary>
  778. /// Mouse down event handler.
  779. /// </summary>
  780. internal void ScrollBar_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  781. {
  782. // Process left mouse button
  783. if(e.Button == MouseButtons.Left && this.IsVisible)
  784. {
  785. // Remember position where mouse was clicked
  786. _lastClickMousePosition = new PointF(e.X, e.Y);
  787. _lastClickViewPosition = this.axis.ScaleView.Position;
  788. // Check if button was pressed inside the scroll bar
  789. ScrollBarButtonType buttonType;
  790. if(GetElementByPixelPosition(e.X, e.Y, out buttonType))
  791. {
  792. this.ButtonClicked(buttonType, e.X, e.Y);
  793. }
  794. }
  795. }
  796. /// <summary>
  797. /// Mouse up event handler.
  798. /// </summary>
  799. internal void ScrollBar_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  800. {
  801. // If scroll bar button was pressed
  802. if(this._pressedButtonType != int.MaxValue)
  803. {
  804. // Check if button was unpressed inside the reset zoom button
  805. ScrollBarButtonType buttonType;
  806. if(GetElementByPixelPosition(e.X, e.Y, out buttonType))
  807. {
  808. if(buttonType == ScrollBarButtonType.ZoomReset)
  809. {
  810. this.ButtonClicked(buttonType, e.X, e.Y);
  811. }
  812. }
  813. // Stop scrolling timer
  814. _scrollTimer.Stop();
  815. _mouseArguments = null;
  816. // Clear pressed button state
  817. this._pressedButtonType = int.MaxValue;
  818. // Invalidate chart
  819. this.axis.Invalidate();
  820. }
  821. }
  822. /// <summary>
  823. /// Mouse move event handler.
  824. /// </summary>
  825. internal void ScrollBar_MouseMove(System.Windows.Forms.MouseEventArgs e, ref bool handled)
  826. {
  827. // If scroll bar button was pressed
  828. if(this._pressedButtonType != int.MaxValue)
  829. {
  830. // Mouse move event should not be handled by any other chart elements
  831. handled = true;
  832. // Check if tracking buton was pressed
  833. if((ScrollBarButtonType)this._pressedButtonType == ScrollBarButtonType.ThumbTracker)
  834. {
  835. // Proceed if last clicked position is known
  836. if(!_lastClickMousePosition.IsEmpty)
  837. {
  838. this.ButtonClicked(ScrollBarButtonType.ThumbTracker, e.X, e.Y);
  839. }
  840. }
  841. // Non tracking scroll bar button
  842. else
  843. {
  844. // Check if mouse cursor is still in the pressed button's rectangle
  845. bool inPressedButton = false;
  846. ScrollBarButtonType buttonType;
  847. if(GetElementByPixelPosition(e.X, e.Y, out buttonType))
  848. {
  849. if(buttonType == (ScrollBarButtonType)this._pressedButtonType)
  850. {
  851. inPressedButton = true;
  852. }
  853. }
  854. // Clear pressed button state
  855. if(!inPressedButton)
  856. {
  857. // Stop scrolling timer
  858. _scrollTimer.Stop();
  859. _mouseArguments = null;
  860. // Clear pressed button state
  861. this._pressedButtonType = int.MaxValue;
  862. // Invalidate chart
  863. this.axis.Invalidate();
  864. }
  865. }
  866. }
  867. }
  868. /// <summary>
  869. /// Scroll bar button was clicked by the user.
  870. /// </summary>
  871. /// <param name="buttonType">Button type.</param>
  872. /// <param name="x">X click position in pixels.</param>
  873. /// <param name="y">Y click position in pixels.</param>
  874. [SuppressMessage("Microsoft.Mobility", "CA1601:DoNotUseTimersThatPreventPowerStateChanges", Justification = "The timer is used for simulating scrolling behavior")]
  875. private void ButtonClicked(ScrollBarButtonType buttonType, int x, int y)
  876. {
  877. // Call zoom reset on the second pass when button is released
  878. if(buttonType != ScrollBarButtonType.ZoomReset ||
  879. (ScrollBarButtonType)this._pressedButtonType == buttonType)
  880. {
  881. //**************************************************
  882. //** Fire scroll bar button clicked event
  883. //**************************************************
  884. ScrollBarEventArgs eventArg = new ScrollBarEventArgs(this.axis, x, y, buttonType);
  885. this.axis.ScaleView.GetChartObject().OnAxisScrollBarClicked(eventArg);
  886. // Check if event was handled by user
  887. if(eventArg.IsHandled)
  888. {
  889. // Save type of the button pressed
  890. this._pressedButtonType = (int)buttonType;
  891. return;
  892. }
  893. //**************************************************
  894. //** Scroll data scaleView
  895. //**************************************************
  896. switch(buttonType)
  897. {
  898. case(ScrollBarButtonType.SmallIncrement):
  899. this.axis.ScaleView.Scroll(ScrollType.SmallIncrement, true);
  900. break;
  901. case(ScrollBarButtonType.SmallDecrement):
  902. this.axis.ScaleView.Scroll(ScrollType.SmallDecrement, true);
  903. break;
  904. case(ScrollBarButtonType.LargeIncrement):
  905. this.axis.ScaleView.Scroll(ScrollType.LargeIncrement, true);
  906. break;
  907. case(ScrollBarButtonType.LargeDecrement):
  908. this.axis.ScaleView.Scroll(ScrollType.LargeDecrement, true);
  909. break;
  910. case(ScrollBarButtonType.ZoomReset):
  911. this.axis.ScaleView.ZoomReset(1, true);
  912. break;
  913. case(ScrollBarButtonType.ThumbTracker):
  914. {
  915. if(!_lastClickMousePosition.IsEmpty &&
  916. !double.IsNaN(this._lastClickViewPosition) &&
  917. (_lastClickMousePosition.X != x || _lastClickMousePosition.Y != y))
  918. {
  919. // Get scroll bar client rectangle
  920. RectangleF scrollBarRect = this.GetScrollBarRect();
  921. SizeF borderRelativeSize = new SizeF(1, 1);
  922. borderRelativeSize = this.GetRelativeSize(borderRelativeSize);
  923. RectangleF scrollBarClientRect = new RectangleF(scrollBarRect.Location, scrollBarRect.Size);
  924. scrollBarClientRect.Inflate(-borderRelativeSize.Width, -borderRelativeSize.Height);
  925. // Check axis orientation
  926. bool verticalAxis = (this.axis.AxisPosition == AxisPosition.Left ||
  927. this.axis.AxisPosition == AxisPosition.Right) ? true : false;
  928. // Get button relative size
  929. SizeF buttonSize = new SizeF(scrollBarClientRect.Width, scrollBarClientRect.Height);
  930. buttonSize = this.GetAbsoluteSize(buttonSize);
  931. if(verticalAxis)
  932. {
  933. buttonSize.Height = buttonSize.Width;
  934. }
  935. else
  936. {
  937. buttonSize.Width = buttonSize.Height;
  938. }
  939. buttonSize = this.GetRelativeSize(buttonSize);
  940. // Calculate the distance in percentages the mouse was moved
  941. // from it's original (clicked) position.
  942. float distance = 0f;
  943. double trackingAreaSize = 0f;
  944. if(verticalAxis)
  945. {
  946. // Calculate max tracking size
  947. trackingAreaSize = scrollBarClientRect.Height - this.GetButtonsNumberAll() * buttonSize.Height;
  948. distance = _lastClickMousePosition.Y - y;
  949. // Convert to relative coordinates
  950. distance = distance * 100F / ((float)(this.axis.Common.Height - 1));
  951. }
  952. else
  953. {
  954. trackingAreaSize = scrollBarClientRect.Width - this.GetButtonsNumberAll() * buttonSize.Width;
  955. distance = x - _lastClickMousePosition.X;
  956. // Convert to relative coordinates
  957. distance = distance * 100F / ((float)(this.axis.Common.Width - 1));
  958. }
  959. // Convert to percentages from total tracking area
  960. distance = (float)(distance / (trackingAreaSize / 100f));
  961. // Get axis scale size without margins
  962. double axisScaleSize = Math.Abs(
  963. (this.axis.maximum - this.axis.marginView) -
  964. (this.axis.minimum + this.axis.marginView));
  965. // Calculate the same percentage using axis scale
  966. distance = (float)(distance * (axisScaleSize/100f));
  967. // Round the distance to the minimum scroll line size
  968. if(!double.IsNaN(axis.ScaleView.SmallScrollMinSize) && axis.ScaleView.SmallScrollMinSize != 0.0)
  969. {
  970. double minSize = ChartHelper.GetIntervalSize(0, axis.ScaleView.SmallScrollMinSize, axis.ScaleView.SmallScrollMinSizeType);
  971. double rounder = (Math.Round(distance / minSize));
  972. distance = (float)(rounder * minSize);
  973. }
  974. // Scroll scaleView into the new position
  975. this.axis.ScaleView.Scroll(this._lastClickViewPosition + ((this.axis.IsReversed) ? -1 : 1) * distance, true);
  976. }
  977. break;
  978. }
  979. }
  980. //************************************************************
  981. //** Initialize timer for repeating scroll (if mouse is hold)
  982. //************************************************************
  983. // Reset mouse arguments
  984. _mouseArguments = null;
  985. if(buttonType != ScrollBarButtonType.ThumbTracker && buttonType != ScrollBarButtonType.ZoomReset)
  986. {
  987. // Remember last mouse position
  988. _mouseArguments = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0);
  989. // Enable timer
  990. if(!_scrollTimer.Enabled)
  991. {
  992. _scrollTimer.Tick += new EventHandler(ScrollingTimerEventProcessor);
  993. _scrollTimer.Interval = 400;
  994. _scrollTimer.Start();
  995. }
  996. }
  997. }
  998. //************************************************************
  999. //** Invalidate chart
  1000. //************************************************************
  1001. // Save type of the button pressed
  1002. this._pressedButtonType = (int)buttonType;
  1003. // Invalidate
  1004. this.axis.Invalidate();
  1005. }
  1006. /// <summary>
  1007. /// This is the method to run when the timer is raised.
  1008. /// Used to repetedly scroll data scaleView while mouse button is pressed.
  1009. /// </summary>
  1010. /// <param name="myObject">Object.</param>
  1011. /// <param name="myEventArgs">Event arguments.</param>
  1012. [SuppressMessage("Microsoft.Mobility", "CA1601:DoNotUseTimersThatPreventPowerStateChanges", Justification = "The timer is used for simulating scrolling behavior")]
  1013. private void ScrollingTimerEventProcessor(Object myObject, EventArgs myEventArgs)
  1014. {
  1015. // Simulate mouse move events
  1016. if(_mouseArguments != null)
  1017. {
  1018. _scrollTimer.Interval = 200;
  1019. this.ScrollBar_MouseDown(null, _mouseArguments);
  1020. }
  1021. }
  1022. /// <summary>
  1023. /// This method fills hot region collection with scroll bar elements.
  1024. /// Possible elements are all scroll bar buttons and scroll bar background
  1025. /// which performs PgUp/PgDn action.
  1026. /// </summary>
  1027. /// <param name="common">Common Elements</param>
  1028. private void SetHotRegionElement( CommonElements common )
  1029. {
  1030. // Check if mouse button was clicked in the scroll bar
  1031. RectangleF scrollBarRect = this.GetScrollBarRect();
  1032. // Get scroll bar client rectangle
  1033. SizeF borderRelativeSize = new SizeF(1, 1);
  1034. borderRelativeSize = this.GetRelativeSize(borderRelativeSize);
  1035. RectangleF scrollBarClientRect = new RectangleF(scrollBarRect.Location, scrollBarRect.Size);
  1036. scrollBarClientRect.Inflate(-borderRelativeSize.Width, -borderRelativeSize.Height);
  1037. ChartElementType buttonType = ChartElementType.Nothing;
  1038. // Fill collection with scroll buttons rectangles.
  1039. foreach(object type in Enum.GetValues(typeof(ScrollBarButtonType)))
  1040. {
  1041. // Convert Scroll Bar Button type enum to Chart Element AxisName enum.
  1042. switch( (ScrollBarButtonType)type )
  1043. {
  1044. case ScrollBarButtonType.SmallIncrement:
  1045. buttonType = ChartElementType.ScrollBarSmallIncrement;
  1046. break;
  1047. case ScrollBarButtonType.LargeIncrement:
  1048. buttonType = ChartElementType.ScrollBarLargeIncrement;
  1049. break;
  1050. case ScrollBarButtonType.LargeDecrement:
  1051. buttonType = ChartElementType.ScrollBarLargeDecrement;
  1052. break;
  1053. case ScrollBarButtonType.ThumbTracker:
  1054. buttonType = ChartElementType.ScrollBarThumbTracker;
  1055. break;
  1056. case ScrollBarButtonType.SmallDecrement:
  1057. buttonType = ChartElementType.ScrollBarSmallDecrement;
  1058. break;
  1059. case ScrollBarButtonType.ZoomReset:
  1060. buttonType = ChartElementType.ScrollBarZoomReset;
  1061. break;
  1062. }
  1063. // Get button rectangle
  1064. RectangleF buttonRect = this.GetScrollBarButtonRect(scrollBarClientRect, (ScrollBarButtonType)type);
  1065. common.HotRegionsList.AddHotRegion( buttonRect, this, buttonType, true );
  1066. }
  1067. }
  1068. /// <summary>
  1069. /// Detects the scroll bar elements by pixel position.
  1070. /// Possible elements are all scroll bar buttons and scroll bar background
  1071. /// which performs PgUp/PgDn action.
  1072. /// </summary>
  1073. /// <param name="x">X coordinate in pixels.</param>
  1074. /// <param name="y">Y coordinate in pixels.</param>
  1075. /// <param name="buttonType">Return button type.</param>
  1076. /// <returns>True if position is in the scroll bar.</returns>
  1077. private bool GetElementByPixelPosition(float x, float y, out ScrollBarButtonType buttonType)
  1078. {
  1079. // Set initial values
  1080. buttonType = ScrollBarButtonType.ThumbTracker;
  1081. // Convert mouse click coordinates to relative
  1082. PointF position = new PointF(x, y);
  1083. position.X = x * 100F / ((float)(this.axis.Common.Width - 1));
  1084. position.Y = y * 100F / ((float)(this.axis.Common.Height - 1));
  1085. // Check if mouse button was clicked in the scroll bar
  1086. RectangleF scrollBarRect = this.GetScrollBarRect();
  1087. if(scrollBarRect.Contains(position))
  1088. {
  1089. // Get scroll bar client rectangle
  1090. SizeF borderRelativeSize = new SizeF(1, 1);
  1091. borderRelativeSize = this.GetRelativeSize(borderRelativeSize);
  1092. RectangleF scrollBarClientRect = new RectangleF(scrollBarRect.Location, scrollBarRect.Size);
  1093. scrollBarClientRect.Inflate(-borderRelativeSize.Width, -borderRelativeSize.Height);
  1094. //******************************************************************
  1095. //** Check if scroll bar button was clicked
  1096. //******************************************************************
  1097. foreach(object type in Enum.GetValues(typeof(ScrollBarButtonType)))
  1098. {
  1099. // Get button rectangle
  1100. RectangleF buttonRect = this.GetScrollBarButtonRect(scrollBarClientRect, (ScrollBarButtonType)type);
  1101. // Check if position is inside the button
  1102. if(buttonRect.Contains(position))
  1103. {
  1104. buttonType = (ScrollBarButtonType)type;
  1105. return true;
  1106. }
  1107. }
  1108. }
  1109. // Pixel position is outside scroll bar area
  1110. return false;
  1111. }
  1112. #endregion
  1113. #region Scroll bar helper methods
  1114. /// <summary>
  1115. /// Returns scroll bar button rectangle position in relative coordinates.
  1116. /// </summary>
  1117. /// <param name="scrollBarClientRect">Scroll bar client rectangle.</param>
  1118. /// <param name="buttonType">Scroll bar button type.</param>
  1119. /// <returns>Scroll bar position.</returns>
  1120. internal RectangleF GetScrollBarButtonRect(RectangleF scrollBarClientRect, ScrollBarButtonType buttonType)
  1121. {
  1122. // Initialize button rectangle
  1123. RectangleF buttonRect = new RectangleF(scrollBarClientRect.Location, scrollBarClientRect.Size);
  1124. // Check axis orientation
  1125. bool verticalAxis = (this.axis.AxisPosition == AxisPosition.Left ||
  1126. this.axis.AxisPosition == AxisPosition.Right) ? true : false;
  1127. // Get relative size of 1 pixel
  1128. SizeF pixelRelativeSize = new SizeF(1, 1);
  1129. pixelRelativeSize = this.GetRelativeSize(pixelRelativeSize);
  1130. // Get button relative size
  1131. SizeF buttonSize = new SizeF(scrollBarClientRect.Width, scrollBarClientRect.Height);
  1132. buttonSize = this.GetAbsoluteSize(buttonSize);
  1133. if(verticalAxis)
  1134. {
  1135. buttonSize.Height = buttonSize.Width;
  1136. }
  1137. else
  1138. {
  1139. buttonSize.Width = buttonSize.Height;
  1140. }
  1141. buttonSize = this.GetRelativeSize(buttonSize);
  1142. // Set common position sizes
  1143. buttonRect.Width = buttonSize.Width;
  1144. buttonRect.Height = buttonSize.Height;
  1145. if(verticalAxis)
  1146. {
  1147. buttonRect.X = scrollBarClientRect.X;
  1148. }
  1149. else
  1150. {
  1151. buttonRect.Y = scrollBarClientRect.Y;
  1152. }
  1153. // Calculate scroll bar buttons position
  1154. switch(buttonType)
  1155. {
  1156. case(ScrollBarButtonType.LargeDecrement):
  1157. case(ScrollBarButtonType.LargeIncrement):
  1158. case(ScrollBarButtonType.ThumbTracker):
  1159. {
  1160. // Get tracker button position and size first
  1161. if(verticalAxis)
  1162. {
  1163. // Calculate tracker size
  1164. double trackingAreaSize = scrollBarClientRect.Height - this.GetButtonsNumberAll() * buttonSize.Height;
  1165. buttonRect.Height = (float)(this.GetDataViewPercentage() * (trackingAreaSize / 100f));
  1166. // Check if tracker size is too small
  1167. if(buttonRect.Height < pixelRelativeSize.Height * 6f)
  1168. {
  1169. buttonRect.Height = pixelRelativeSize.Height * 6f;
  1170. }
  1171. // Calculate tracker position
  1172. if(!this.axis.IsReversed)
  1173. {
  1174. buttonRect.Y = scrollBarClientRect.Bottom - this.GetButtonsNumberBottom()*buttonSize.Height - buttonRect.Height;
  1175. buttonRect.Y -= (float)(this.GetDataViewPositionPercentage() * (trackingAreaSize / 100f));
  1176. if(buttonRect.Y < scrollBarClientRect.Y + this.GetButtonsNumberTop()*buttonSize.Height + ((this.GetButtonsNumberTop() == 0) ? 0 : pixelRelativeSize.Height))
  1177. {
  1178. buttonRect.Y = scrollBarClientRect.Y + this.GetButtonsNumberTop()*buttonSize.Height + ((this.GetButtonsNumberTop() == 0) ? 0 : pixelRelativeSize.Height);
  1179. }
  1180. }
  1181. else
  1182. {
  1183. buttonRect.Y = scrollBarClientRect.Top + this.GetButtonsNumberTop()*buttonSize.Height;
  1184. buttonRect.Y += (float)(this.GetDataViewPositionPercentage() * (trackingAreaSize / 100f));
  1185. if((buttonRect.Y + buttonRect.Height) > scrollBarClientRect.Bottom - this.GetButtonsNumberBottom()*buttonSize.Height - ((this.GetButtonsNumberBottom() == 0) ? 0 : pixelRelativeSize.Height))
  1186. {
  1187. buttonRect.Y = (scrollBarClientRect.Bottom - this.GetButtonsNumberBottom()*buttonSize.Height) - buttonRect.Height - ((this.GetButtonsNumberBottom() == 0) ? 0 : pixelRelativeSize.Height);
  1188. }
  1189. }
  1190. }
  1191. else
  1192. {
  1193. // Calculate tracker size
  1194. double trackingAreaSize = scrollBarClientRect.Width - this.GetButtonsNumberAll() * buttonSize.Width;
  1195. buttonRect.Width = (float)(this.GetDataViewPercentage() * (trackingAreaSize / 100f));
  1196. // Check if tracker size is too small
  1197. if(buttonRect.Width < pixelRelativeSize.Width * 6f)
  1198. {
  1199. buttonRect.Width = pixelRelativeSize.Width * 6f;
  1200. }
  1201. // Calculate tracker position
  1202. if(!this.axis.IsReversed)
  1203. {
  1204. buttonRect.X = scrollBarClientRect.X + this.GetButtonsNumberTop() * buttonSize.Width;
  1205. buttonRect.X += (float)(this.GetDataViewPositionPercentage() * (trackingAreaSize / 100f));
  1206. if((buttonRect.X + buttonRect.Width) > scrollBarClientRect.Right - this.GetButtonsNumberBottom()*buttonSize.Width - ((this.GetButtonsNumberBottom() == 0) ? 0 : pixelRelativeSize.Width))
  1207. {
  1208. buttonRect.X = (scrollBarClientRect.Right - buttonRect.Width) - this.GetButtonsNumberBottom()*buttonSize.Width - ((this.GetButtonsNumberBottom() == 0) ? 0 : pixelRelativeSize.Width);
  1209. }
  1210. }
  1211. else
  1212. {
  1213. buttonRect.X = scrollBarClientRect.Right - this.GetButtonsNumberBottom()*buttonSize.Width - ((this.GetButtonsNumberBottom() == 0) ? 0 : pixelRelativeSize.Width) - buttonRect.Width;
  1214. buttonRect.X -= (float)(this.GetDataViewPositionPercentage() * (trackingAreaSize / 100f));
  1215. if(buttonRect.X < scrollBarClientRect.X + this.GetButtonsNumberTop()*buttonSize.Width)
  1216. {
  1217. buttonRect.X = scrollBarClientRect.X + this.GetButtonsNumberTop()*buttonSize.Width;
  1218. }
  1219. }
  1220. }
  1221. // Get page up region rectangle depending on the tracker position
  1222. if(buttonType == ScrollBarButtonType.LargeDecrement)
  1223. {
  1224. if(verticalAxis)
  1225. {
  1226. buttonRect.Y = buttonRect.Bottom + pixelRelativeSize.Height;
  1227. buttonRect.Height = (scrollBarClientRect.Bottom - this.GetButtonsNumberBottom()*buttonSize.Height - pixelRelativeSize.Height) - buttonRect.Y;
  1228. }
  1229. else
  1230. {
  1231. float x = scrollBarClientRect.X +
  1232. this.GetButtonsNumberTop() * buttonSize.Width +
  1233. pixelRelativeSize.Width;
  1234. buttonRect.Width = buttonRect.X - x;
  1235. buttonRect.X = x;
  1236. }
  1237. }
  1238. // Get page down region rectangle depending on the tracker position
  1239. else if(buttonType == ScrollBarButtonType.LargeIncrement)
  1240. {
  1241. if(verticalAxis)
  1242. {
  1243. float y = scrollBarClientRect.Y +
  1244. this.GetButtonsNumberTop() * buttonSize.Height +
  1245. pixelRelativeSize.Height;
  1246. buttonRect.Height = buttonRect.Y - y;
  1247. buttonRect.Y = y;
  1248. }
  1249. else
  1250. {
  1251. buttonRect.X = buttonRect.Right + pixelRelativeSize.Width;
  1252. buttonRect.Width = (scrollBarClientRect.Right - this.GetButtonsNumberBottom()*buttonSize.Width - pixelRelativeSize.Height) - buttonRect.X;
  1253. }
  1254. }
  1255. break;
  1256. }
  1257. case(ScrollBarButtonType.SmallDecrement):
  1258. if(this._scrollBarButtonStyle == ScrollBarButtonStyles.All ||
  1259. this._scrollBarButtonStyle == ScrollBarButtonStyles.SmallScroll)
  1260. {
  1261. if(verticalAxis)
  1262. {
  1263. buttonRect.Y = scrollBarClientRect.Bottom - buttonRect.Height;
  1264. }
  1265. else
  1266. {
  1267. buttonRect.X = scrollBarClientRect.X + (this.GetButtonsNumberTop()-1f)*buttonSize.Width;
  1268. buttonRect.X += (this.GetButtonsNumberTop() == 1) ? 0 : pixelRelativeSize.Width;
  1269. }
  1270. }
  1271. else
  1272. {
  1273. buttonRect = RectangleF.Empty;
  1274. }
  1275. break;
  1276. case(ScrollBarButtonType.SmallIncrement):
  1277. if(this._scrollBarButtonStyle == ScrollBarButtonStyles.All ||
  1278. this._scrollBarButtonStyle == ScrollBarButtonStyles.SmallScroll)
  1279. {
  1280. if(verticalAxis)
  1281. {
  1282. buttonRect.Y = scrollBarClientRect.Y + (this.GetButtonsNumberTop()-1f) * buttonSize.Height;
  1283. buttonRect.Y += (this.GetButtonsNumberTop() == 1) ? 0 : pixelRelativeSize.Height;
  1284. }
  1285. else
  1286. {
  1287. buttonRect.X = scrollBarClientRect.Right - buttonRect.Width;
  1288. }
  1289. }
  1290. else
  1291. {
  1292. buttonRect = RectangleF.Empty;
  1293. }
  1294. break;
  1295. case(ScrollBarButtonType.ZoomReset):
  1296. if(this._scrollBarButtonStyle == ScrollBarButtonStyles.All ||
  1297. this._scrollBarButtonStyle == ScrollBarButtonStyles.ResetZoom)
  1298. {
  1299. if(verticalAxis)
  1300. {
  1301. buttonRect.Y = scrollBarClientRect.Y;
  1302. }
  1303. else
  1304. {
  1305. buttonRect.X = scrollBarClientRect.X;
  1306. }
  1307. }
  1308. else
  1309. {
  1310. buttonRect = RectangleF.Empty;
  1311. }
  1312. break;
  1313. }
  1314. return buttonRect;
  1315. }
  1316. /// <summary>
  1317. /// Returns scroll bar rectangle position in relative coordinates.
  1318. /// </summary>
  1319. /// <returns>Scroll bar position.</returns>
  1320. internal RectangleF GetScrollBarRect()
  1321. {
  1322. // Get scroll bar relative size
  1323. float scrollBarSize = (float)this.GetScrollBarRelativeSize();
  1324. // Get relative size of the axis line (Note: Code removed for now. -- AG)
  1325. //SizeF axisLineSize = new SizeF(axis.LineWidth, axis.LineWidth);
  1326. //axisLineSize.Width = axisLineSize.Width * 100F / ((float)(this.axis.Common.Width - 1));
  1327. //axisLineSize.Height = axisLineSize.Height * 100F / ((float)(this.axis.Common.Height - 1));
  1328. // Check if scroll bar is positioned next to PlotArea or ChartArea
  1329. RectangleF areaPosition = axis.PlotAreaPosition.ToRectangleF();
  1330. if(!this.IsPositionedInside)
  1331. {
  1332. areaPosition = axis.ChartArea.Position.ToRectangleF();
  1333. // Reduce rectangle size by scroll bar size
  1334. foreach(Axis a in this.ChartArea.Axes)
  1335. {
  1336. if(a.ScrollBar.IsVisible && !a.ScrollBar.IsPositionedInside)
  1337. {
  1338. float size = (float)a.ScrollBar.GetScrollBarRelativeSize();
  1339. switch( a.AxisPosition )
  1340. {
  1341. case AxisPosition.Left:
  1342. areaPosition.X += size;
  1343. areaPosition.Width -= size;
  1344. break;
  1345. case AxisPosition.Right:
  1346. areaPosition.Width -= size;
  1347. break;
  1348. case AxisPosition.Bottom:
  1349. areaPosition.Height -= size;
  1350. break;
  1351. case AxisPosition.Top:
  1352. areaPosition.Y += size;
  1353. areaPosition.Height -= size;
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. }
  1359. // Get bar position depending on the axis type
  1360. RectangleF barPosition = RectangleF.Empty;
  1361. if(this.axis.PlotAreaPosition != null)
  1362. {
  1363. switch( axis.AxisPosition )
  1364. {
  1365. case AxisPosition.Left:
  1366. barPosition.Y = areaPosition.Y;
  1367. barPosition.Height = areaPosition.Height;
  1368. barPosition.X =
  1369. ( (this.IsPositionedInside) ? (float)(axis.GetAxisPosition(true)) : areaPosition.X) - scrollBarSize;// - axisLineSize.Width / 2f;
  1370. barPosition.Width = scrollBarSize;
  1371. break;
  1372. case AxisPosition.Right:
  1373. barPosition.Y = areaPosition.Y;
  1374. barPosition.Height = areaPosition.Height;
  1375. barPosition.X =
  1376. (this.IsPositionedInside) ? (float)axis.GetAxisPosition(true) : areaPosition.Right;// + axisLineSize.Width / 2f;
  1377. barPosition.Width = scrollBarSize;
  1378. break;
  1379. case AxisPosition.Bottom:
  1380. barPosition.X = areaPosition.X;
  1381. barPosition.Width = areaPosition.Width;
  1382. barPosition.Y =
  1383. (this.IsPositionedInside) ? (float)axis.GetAxisPosition(true) : areaPosition.Bottom;// + axisLineSize.Height / 2f;
  1384. barPosition.Height = scrollBarSize;
  1385. break;
  1386. case AxisPosition.Top:
  1387. barPosition.X = areaPosition.X;
  1388. barPosition.Width = areaPosition.Width;
  1389. barPosition.Y =
  1390. ( (this.IsPositionedInside) ? (float)axis.GetAxisPosition(true) : areaPosition.Y) - scrollBarSize;// - axisLineSize.Height / 2f;
  1391. barPosition.Height = scrollBarSize;
  1392. break;
  1393. }
  1394. }
  1395. return barPosition;
  1396. }
  1397. /// <summary>
  1398. /// Internal helper method which returns the relative scroll bar size.
  1399. /// </summary>
  1400. /// <returns>Relative scroll bar size.</returns>
  1401. internal double GetScrollBarRelativeSize()
  1402. {
  1403. // Scroll bar is not shown in 3D
  1404. if(this.axis.ChartArea.Area3DStyle.Enable3D || this.axis.ChartArea.chartAreaIsCurcular)
  1405. {
  1406. return 0.0;
  1407. }
  1408. #if SUBAXES
  1409. // Scrollbar not supported on sub axis
  1410. if( this.axis != null && this.axis.IsSubAxis)
  1411. {
  1412. return 0.0;
  1413. }
  1414. #endif //SUBAXES
  1415. // Get scroll bar relative size depending on the axis location
  1416. if(this.axis.AxisPosition == AxisPosition.Left || this.axis.AxisPosition == AxisPosition.Right)
  1417. {
  1418. return this._scrollBarSize * 100F / ((float)(this.axis.Common.Width - 1));
  1419. }
  1420. else
  1421. {
  1422. return this._scrollBarSize * 100F / ((float)(this.axis.Common.Height - 1));
  1423. }
  1424. }
  1425. /// <summary>
  1426. /// Returns the percentage size (0-100%) of the data scaleView comparing to
  1427. /// the axis scale minimum and maximum values.
  1428. /// </summary>
  1429. /// <returns>Size of the data scaleView in percentage.</returns>
  1430. private double GetDataViewPercentage()
  1431. {
  1432. double viewPercentage = 100.0;
  1433. // Check if axis data scaleView properties are set
  1434. if(this.axis != null &&
  1435. !double.IsNaN(this.axis.ScaleView.Position) &&
  1436. !double.IsNaN(this.axis.ScaleView.Size))
  1437. {
  1438. // Get data scaleView size
  1439. double dataViewSize = ChartHelper.GetIntervalSize(
  1440. this.axis.ScaleView.Position,
  1441. this.axis.ScaleView.Size,
  1442. this.axis.ScaleView.SizeType);
  1443. // Get axis scale size without margins
  1444. double minimum = this.axis.minimum + this.axis.marginView;
  1445. double maximum = this.axis.maximum - this.axis.marginView;
  1446. if(this.axis.ScaleView.Position < minimum)
  1447. {
  1448. minimum = this.axis.ScaleView.Position;
  1449. }
  1450. if((this.axis.ScaleView.Position + dataViewSize) > maximum)
  1451. {
  1452. maximum = this.axis.ScaleView.Position + dataViewSize;
  1453. }
  1454. double axisScaleSize = Math.Abs(minimum - maximum);
  1455. // Check if data scaleView is smaller than axis scale and if it is find the pecentage
  1456. if(dataViewSize < axisScaleSize)
  1457. {
  1458. viewPercentage = dataViewSize / (axisScaleSize / 100.0);
  1459. }
  1460. }
  1461. return viewPercentage;
  1462. }
  1463. /// <summary>
  1464. /// Returns the the data scaleView position in percentage (0-100%) using
  1465. /// the axis scale minimum and maximum values.
  1466. /// </summary>
  1467. /// <returns>Data scaleView position in percentage.</returns>
  1468. private double GetDataViewPositionPercentage()
  1469. {
  1470. double viewPosition = 0.0;
  1471. // Check if axis data scaleView properties are set
  1472. if(this.axis != null &&
  1473. !double.IsNaN(this.axis.ScaleView.Position) &&
  1474. !double.IsNaN(this.axis.ScaleView.Size))
  1475. {
  1476. // Get data scaleView size
  1477. double dataViewSize = ChartHelper.GetIntervalSize(
  1478. this.axis.ScaleView.Position,
  1479. this.axis.ScaleView.Size,
  1480. this.axis.ScaleView.SizeType);
  1481. // Get axis scale size without margins
  1482. double minimum = this.axis.minimum + this.axis.marginView;
  1483. double maximum = this.axis.maximum - this.axis.marginView;
  1484. if(this.axis.ScaleView.Position < minimum)
  1485. {
  1486. minimum = this.axis.ScaleView.Position;
  1487. }
  1488. if((this.axis.ScaleView.Position + dataViewSize) > maximum)
  1489. {
  1490. maximum = this.axis.ScaleView.Position + dataViewSize;
  1491. }
  1492. double axisScaleSize = Math.Abs(minimum - maximum);
  1493. // Calculate data scaleView position in percentage
  1494. viewPosition = (this.axis.ScaleView.Position - (minimum)) / (axisScaleSize / 100.0);
  1495. }
  1496. return viewPosition;
  1497. }
  1498. /// <summary>
  1499. /// Get total number of buttons in the scroll bar (except tracker).
  1500. /// </summary>
  1501. /// <returns>Number of buttons.</returns>
  1502. private int GetButtonsNumberAll()
  1503. {
  1504. int buttonNumber = 0;
  1505. if((this._scrollBarButtonStyle & ScrollBarButtonStyles.ResetZoom) == ScrollBarButtonStyles.ResetZoom)
  1506. {
  1507. buttonNumber += 1;
  1508. }
  1509. if((this._scrollBarButtonStyle & ScrollBarButtonStyles.SmallScroll) == ScrollBarButtonStyles.SmallScroll)
  1510. {
  1511. buttonNumber += 2;
  1512. }
  1513. return buttonNumber;
  1514. }
  1515. /// <summary>
  1516. /// Get number of buttons in the top (left) part of the scroll bar.
  1517. /// </summary>
  1518. /// <returns>Number of buttons.</returns>
  1519. private int GetButtonsNumberTop()
  1520. {
  1521. int buttonNumber = 0;
  1522. if((this._scrollBarButtonStyle & ScrollBarButtonStyles.ResetZoom) == ScrollBarButtonStyles.ResetZoom)
  1523. {
  1524. buttonNumber += 1;
  1525. }
  1526. if((this._scrollBarButtonStyle & ScrollBarButtonStyles.SmallScroll) == ScrollBarButtonStyles.SmallScroll)
  1527. {
  1528. buttonNumber += 1;
  1529. }
  1530. return buttonNumber;
  1531. }
  1532. /// <summary>
  1533. /// Get number of buttons in the bottom (right) part of the scroll bar.
  1534. /// </summary>
  1535. /// <returns>Number of buttons.</returns>
  1536. private int GetButtonsNumberBottom()
  1537. {
  1538. int buttonNumber = 0;
  1539. if((this._scrollBarButtonStyle & ScrollBarButtonStyles.SmallScroll) == ScrollBarButtonStyles.SmallScroll)
  1540. {
  1541. buttonNumber += 1;
  1542. }
  1543. return buttonNumber;
  1544. }
  1545. #endregion
  1546. #region Coordinate convertion methods
  1547. /// <summary>
  1548. /// Converts Relative size to Absolute size
  1549. /// </summary>
  1550. /// <param name="relative">Relative size in %</param>
  1551. /// <returns>Absolute size</returns>
  1552. internal SizeF GetAbsoluteSize( SizeF relative )
  1553. {
  1554. SizeF absolute = SizeF.Empty;
  1555. // Convert relative coordinates to absolute coordinates
  1556. absolute.Width = relative.Width * (this.axis.Common.Width - 1) / 100F;
  1557. absolute.Height = relative.Height * (this.axis.Common.Height - 1) / 100F;
  1558. // Return Absolute coordinates
  1559. return absolute;
  1560. }
  1561. /// <summary>
  1562. /// Converts Absolute size to Relative size
  1563. /// </summary>
  1564. /// <param name="size">Absolute size</param>
  1565. /// <returns>Relative size</returns>
  1566. internal SizeF GetRelativeSize( SizeF size )
  1567. {
  1568. SizeF relative = SizeF.Empty;
  1569. // Convert absolute coordinates to relative coordinates
  1570. relative.Width = size.Width * 100F / ((float)(this.axis.Common.Width - 1));
  1571. relative.Height = size.Height * 100F / ((float)(this.axis.Common.Height - 1));
  1572. // Return relative coordinates
  1573. return relative;
  1574. }
  1575. #endregion
  1576. #region IDisposable Members
  1577. /// <summary>
  1578. /// Releases unmanaged and - optionally - managed resources
  1579. /// </summary>
  1580. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  1581. protected virtual void Dispose(bool disposing)
  1582. {
  1583. if (disposing)
  1584. {
  1585. // Dispose managed resources
  1586. if (this._scrollTimer != null)
  1587. {
  1588. this._scrollTimer.Dispose();
  1589. this._scrollTimer = null;
  1590. }
  1591. }
  1592. }
  1593. /// <summary>
  1594. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  1595. /// </summary>
  1596. public void Dispose()
  1597. {
  1598. Dispose(true);
  1599. GC.SuppressFinalize(this);
  1600. }
  1601. #endregion
  1602. }
  1603. /// <summary>
  1604. /// The arguments for a scrollbar event.
  1605. /// </summary>
  1606. public class ScrollBarEventArgs : EventArgs
  1607. {
  1608. #region Private fields
  1609. // Private fields for properties values storage
  1610. private Axis _axis = null;
  1611. private bool _isHandled = false;
  1612. private int _mousePositionX = 0;
  1613. private int _mousePositionY = 0;
  1614. private ScrollBarButtonType _buttonType = ScrollBarButtonType.ThumbTracker;
  1615. #endregion
  1616. #region Constructors
  1617. /// <summary>
  1618. /// ScrollBarEventArgs constructor.
  1619. /// </summary>
  1620. /// <param name="axis">Axis containing the scrollbar.</param>
  1621. /// <param name="x">X position of mouse cursor.</param>
  1622. /// <param name="y">Y position of mouse cursor.</param>
  1623. /// <param name="buttonType">Button type of the button clicked.</param>
  1624. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1625. Justification = "X and Y are cartesian coordinates and well understood")]
  1626. public ScrollBarEventArgs(Axis axis, int x, int y, ScrollBarButtonType buttonType)
  1627. {
  1628. this._axis = axis;
  1629. this._mousePositionX = x;
  1630. this._mousePositionY = y;
  1631. this._buttonType = buttonType;
  1632. }
  1633. #endregion
  1634. #region Properties
  1635. /// <summary>
  1636. /// Axis containing the scrollbar of the event.
  1637. /// </summary>
  1638. [
  1639. SRDescription("DescriptionAttributeAxis"),
  1640. ]
  1641. public Axis Axis
  1642. {
  1643. get
  1644. {
  1645. return _axis;
  1646. }
  1647. }
  1648. /// <summary>
  1649. /// ChartArea containing the scrollbar of the event.
  1650. /// </summary>
  1651. [
  1652. SRDescription("DescriptionAttributeChartArea"),
  1653. ]
  1654. public ChartArea ChartArea
  1655. {
  1656. get
  1657. {
  1658. return _axis.ChartArea;
  1659. }
  1660. }
  1661. /// <summary>
  1662. /// Button type of the scrollbar button clicked.
  1663. /// </summary>
  1664. [
  1665. SRDescription("DescriptionAttributeScrollBarEventArgs_ButtonType"),
  1666. ]
  1667. public ScrollBarButtonType ButtonType
  1668. {
  1669. get
  1670. {
  1671. return _buttonType;
  1672. }
  1673. }
  1674. /// <summary>
  1675. /// Indicates if the event is handled by the user and no further processing is required.
  1676. /// </summary>
  1677. [
  1678. SRDescription("DescriptionAttributeScrollBarEventArgs_Handled"),
  1679. ]
  1680. public bool IsHandled
  1681. {
  1682. get
  1683. {
  1684. return _isHandled;
  1685. }
  1686. set
  1687. {
  1688. _isHandled = value;
  1689. }
  1690. }
  1691. /// <summary>
  1692. /// X position of mouse cursor.
  1693. /// </summary>
  1694. [
  1695. SRDescription("DescriptionAttributeScrollBarEventArgs_MousePositionX"),
  1696. ]
  1697. public int MousePositionX
  1698. {
  1699. get
  1700. {
  1701. return _mousePositionX;
  1702. }
  1703. }
  1704. /// <summary>
  1705. /// Y position of mouse cursor.
  1706. /// </summary>
  1707. [
  1708. SRDescription("DescriptionAttributeScrollBarEventArgs_MousePositionY"),
  1709. ]
  1710. public int MousePositionY
  1711. {
  1712. get
  1713. {
  1714. return _mousePositionY;
  1715. }
  1716. }
  1717. #endregion
  1718. }
  1719. }