NumberCellEditor.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. //#########################################################################################
  2. //★★★★★★★ http://www.cnpopsoft.com [华普软件] ★★★★★★★
  3. //★★★★★★★ 华普软件 - VB & C#.NET 专业论文与源码荟萃! ★★★★★★★
  4. //#########################################################################################
  5. /*
  6. * Copyright ?2005, Mathew Hall
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  25. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. * OF SUCH DAMAGE.
  29. */
  30. using System;
  31. using System.Drawing;
  32. using System.Globalization;
  33. using System.Windows.Forms;
  34. using XPTable.Events;
  35. using XPTable.Models;
  36. using XPTable.Renderers;
  37. using XPTable.Win32;
  38. namespace XPTable.Editors
  39. {
  40. /// <summary>
  41. /// A class for editing Cells that contain numbers
  42. /// </summary>
  43. public class NumberCellEditor : CellEditor, IEditorUsesRendererButtons
  44. {
  45. #region Class Data
  46. /// <summary>
  47. /// ID number for the up button
  48. /// </summary>
  49. protected static readonly int UpButtonID = 1;
  50. /// <summary>
  51. /// ID number for the down button
  52. /// </summary>
  53. protected static readonly int DownButtonID = 2;
  54. /// <summary>
  55. /// The current value of the editor
  56. /// </summary>
  57. private decimal currentValue;
  58. /// <summary>
  59. /// The value to increment or decrement when the up or down buttons are clicked
  60. /// </summary>
  61. private decimal increment;
  62. /// <summary>
  63. /// The maximum value for the editor
  64. /// </summary>
  65. private decimal maximum;
  66. /// <summary>
  67. /// The inximum value for the editor
  68. /// </summary>
  69. private decimal minimum;
  70. /// <summary>
  71. /// A string that specifies how editors value is formatted
  72. /// </summary>
  73. private string format;
  74. /// <summary>
  75. /// The amount the mouse wheel has moved
  76. /// </summary>
  77. private int wheelDelta;
  78. /// <summary>
  79. /// Indicates whether the arrow keys should be passed to the editor
  80. /// </summary>
  81. private bool interceptArrowKeys;
  82. /// <summary>
  83. /// Specifies whether the editors text value is changing
  84. /// </summary>
  85. private bool changingText;
  86. /// <summary>
  87. /// Initial interval between timer events
  88. /// </summary>
  89. private const int TimerInterval = 500;
  90. /// <summary>
  91. /// Current interval between timer events
  92. /// </summary>
  93. private int interval;
  94. /// <summary>
  95. /// Indicates whether the user has changed the editors value
  96. /// </summary>
  97. private bool userEdit;
  98. /// <summary>
  99. /// The bounding Rectangle of the up and down buttons
  100. /// </summary>
  101. private Rectangle buttonBounds;
  102. /// <summary>
  103. /// The id of the button that was pressed
  104. /// </summary>
  105. private int buttonID;
  106. /// <summary>
  107. /// Timer to to fire button presses at regular intervals while
  108. /// a button is pressed
  109. /// </summary>
  110. private Timer timer;
  111. #endregion
  112. #region Constructor
  113. /// <summary>
  114. /// Initializes a new instance of the NumberCellEditor class with default settings
  115. /// </summary>
  116. public NumberCellEditor()
  117. {
  118. TextBox textbox = new TextBox();
  119. textbox.AutoSize = false;
  120. textbox.BorderStyle = BorderStyle.None;
  121. this.Control = textbox;
  122. this.currentValue = new decimal(0);
  123. this.increment = new decimal(1);
  124. this.minimum = new decimal(0);
  125. this.maximum = new decimal(100);
  126. this.format = "G";
  127. this.wheelDelta = 0;
  128. this.interceptArrowKeys = true;
  129. this.userEdit = false;
  130. this.changingText = false;
  131. this.buttonBounds = Rectangle.Empty;
  132. this.buttonID = 0;
  133. this.interval = TimerInterval;
  134. }
  135. #endregion
  136. #region Methods
  137. /// <summary>
  138. /// Prepares the CellEditor to edit the specified Cell
  139. /// </summary>
  140. /// <param name="cell">The Cell to be edited</param>
  141. /// <param name="table">The Table that contains the Cell</param>
  142. /// <param name="cellPos">A CellPos representing the position of the Cell</param>
  143. /// <param name="cellRect">The Rectangle that represents the Cells location and size</param>
  144. /// <param name="userSetEditorValues">Specifies whether the ICellEditors
  145. /// starting value has already been set by the user</param>
  146. /// <returns>true if the ICellEditor can continue editing the Cell, false otherwise</returns>
  147. public override bool PrepareForEditing(Cell cell, Table table, CellPos cellPos, Rectangle cellRect, bool userSetEditorValues)
  148. {
  149. //
  150. if (!(table.ColumnModel.Columns[cellPos.Column] is NumberColumn))
  151. {
  152. throw new InvalidOperationException("Cannot edit Cell as NumberCellEditor can only be used with a NumberColumn");
  153. }
  154. if (!(table.ColumnModel.GetCellRenderer(cellPos.Column) is NumberCellRenderer))
  155. {
  156. throw new InvalidOperationException("Cannot edit Cell as NumberCellEditor can only be used with a NumberColumn that uses a NumberCellRenderer");
  157. }
  158. this.Minimum = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Minimum;
  159. this.Maximum = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Maximum;
  160. this.Increment = ((NumberColumn) table.ColumnModel.Columns[cellPos.Column]).Increment;
  161. return base.PrepareForEditing (cell, table, cellPos, cellRect, userSetEditorValues);
  162. }
  163. /// <summary>
  164. /// Sets the initial value of the editor based on the contents of
  165. /// the Cell being edited
  166. /// </summary>
  167. protected override void SetEditValue()
  168. {
  169. // make sure we start with a valid value
  170. this.Value = this.Minimum;
  171. // attempt to get the cells data
  172. this.Value = Convert.ToDecimal(this.EditingCell.Data);
  173. }
  174. /// <summary>
  175. /// Sets the contents of the Cell being edited based on the value
  176. /// in the editor
  177. /// </summary>
  178. protected override void SetCellValue()
  179. {
  180. this.EditingCell.Data = this.Value;
  181. }
  182. /// <summary>
  183. /// Starts editing the Cell
  184. /// </summary>
  185. public override void StartEditing()
  186. {
  187. this.TextBox.MouseWheel += new MouseEventHandler(OnMouseWheel);
  188. this.TextBox.KeyDown += new KeyEventHandler(OnTextBoxKeyDown);
  189. this.TextBox.KeyPress += new KeyPressEventHandler(OnTextBoxKeyPress);
  190. this.TextBox.LostFocus += new EventHandler(OnTextBoxLostFocus);
  191. base.StartEditing();
  192. this.TextBox.Focus();
  193. }
  194. /// <summary>
  195. /// Stops editing the Cell and commits any changes
  196. /// </summary>
  197. public override void StopEditing()
  198. {
  199. this.TextBox.MouseWheel -= new MouseEventHandler(OnMouseWheel);
  200. this.TextBox.KeyDown -= new KeyEventHandler(OnTextBoxKeyDown);
  201. this.TextBox.KeyPress -= new KeyPressEventHandler(OnTextBoxKeyPress);
  202. this.TextBox.LostFocus -= new EventHandler(OnTextBoxLostFocus);
  203. base.StopEditing();
  204. }
  205. /// <summary>
  206. /// Stops editing the Cell and ignores any changes
  207. /// </summary>
  208. public override void CancelEditing()
  209. {
  210. this.TextBox.MouseWheel -= new MouseEventHandler(OnMouseWheel);
  211. this.TextBox.KeyDown -= new KeyEventHandler(OnTextBoxKeyDown);
  212. this.TextBox.KeyPress -= new KeyPressEventHandler(OnTextBoxKeyPress);
  213. this.TextBox.LostFocus -= new EventHandler(OnTextBoxLostFocus);
  214. base.CancelEditing();
  215. }
  216. /// <summary>
  217. /// Sets the location and size of the CellEditor
  218. /// </summary>
  219. /// <param name="cellRect">A Rectangle that represents the size and location
  220. /// of the Cell being edited</param>
  221. protected override void SetEditLocation(Rectangle cellRect)
  222. {
  223. // calc the size of the textbox
  224. ICellRenderer renderer = this.EditingTable.ColumnModel.GetCellRenderer(this.EditingCellPos.Column);
  225. int buttonWidth = ((NumberCellRenderer) renderer).ButtonWidth;
  226. this.TextBox.Size = new Size(cellRect.Width - 1 - buttonWidth, cellRect.Height-1);
  227. // calc the location of the textbox
  228. this.TextBox.Location = cellRect.Location;
  229. this.buttonBounds = new Rectangle(this.TextBox.Left + 1, this.TextBox.Top, buttonWidth, this.TextBox.Height);
  230. if (((NumberColumn) this.EditingTable.ColumnModel.Columns[this.EditingCellPos.Column]).UpDownAlign == LeftRightAlignment.Left)
  231. {
  232. this.TextBox.Location = new Point(cellRect.Left + buttonWidth, cellRect.Top);
  233. this.buttonBounds.Location = new Point(cellRect.Left, cellRect.Top);
  234. }
  235. }
  236. /// <summary>
  237. /// Simulates the up button being pressed
  238. /// </summary>
  239. protected void UpButton()
  240. {
  241. if (this.UserEdit)
  242. {
  243. this.ParseEditText();
  244. }
  245. decimal num = this.currentValue;
  246. if (num > (new decimal(-1, -1, -1, false, 0) - this.increment))
  247. {
  248. num = new decimal(-1, -1, -1, false, 0);
  249. }
  250. else
  251. {
  252. num += this.increment;
  253. if (num > this.maximum)
  254. {
  255. num = this.maximum;
  256. }
  257. }
  258. this.Value = num;
  259. }
  260. /// <summary>
  261. /// Simulates the down button being pressed
  262. /// </summary>
  263. protected void DownButton()
  264. {
  265. if (this.UserEdit)
  266. {
  267. this.ParseEditText();
  268. }
  269. decimal num = this.currentValue;
  270. if (num < (new decimal(-1, -1, -1, true, 0) + this.increment))
  271. {
  272. num = new decimal(-1, -1, -1, true, 0);
  273. }
  274. else
  275. {
  276. num -= this.increment;
  277. if (num < this.minimum)
  278. {
  279. num = this.minimum;
  280. }
  281. }
  282. this.Value = num;
  283. }
  284. /// <summary>
  285. /// Updates the editors text value to the current value
  286. /// </summary>
  287. protected void UpdateEditText()
  288. {
  289. if (this.UserEdit)
  290. {
  291. this.ParseEditText();
  292. }
  293. this.ChangingText = true;
  294. this.Control.Text = this.currentValue.ToString(this.Format);
  295. }
  296. /// <summary>
  297. /// Checks the current value and updates the editors text value
  298. /// </summary>
  299. protected virtual void ValidateEditText()
  300. {
  301. this.ParseEditText();
  302. this.UpdateEditText();
  303. }
  304. /// <summary>
  305. /// Converts the editors current value to a number
  306. /// </summary>
  307. protected void ParseEditText()
  308. {
  309. try
  310. {
  311. this.Value = this.Constrain(decimal.Parse(this.Control.Text));
  312. }
  313. catch (Exception)
  314. {
  315. return;
  316. }
  317. finally
  318. {
  319. this.UserEdit = false;
  320. }
  321. }
  322. /// <summary>
  323. /// Ensures that the specified value is between the editors Maximun and
  324. /// Minimum values
  325. /// </summary>
  326. /// <param name="value">The value to be checked</param>
  327. /// <returns>A value is between the editors Maximun and Minimum values</returns>
  328. private decimal Constrain(decimal value)
  329. {
  330. if (value < this.minimum)
  331. {
  332. value = this.minimum;
  333. }
  334. if (value > this.maximum)
  335. {
  336. value = this.maximum;
  337. }
  338. return value;
  339. }
  340. /// <summary>
  341. /// Starts the Timer
  342. /// </summary>
  343. protected void StartTimer()
  344. {
  345. if (this.timer == null)
  346. {
  347. this.timer = new Timer();
  348. this.timer.Tick += new EventHandler(this.TimerHandler);
  349. }
  350. this.interval = TimerInterval;
  351. this.timer.Interval = this.interval;
  352. this.timer.Start();
  353. }
  354. /// <summary>
  355. /// Stops the Timer
  356. /// </summary>
  357. protected void StopTimer()
  358. {
  359. if (this.timer != null)
  360. {
  361. this.timer.Stop();
  362. this.timer.Dispose();
  363. this.timer = null;
  364. }
  365. }
  366. #endregion
  367. #region Properties
  368. /// <summary>
  369. /// Gets the TextBox used to edit the Cells contents
  370. /// </summary>
  371. public TextBox TextBox
  372. {
  373. get
  374. {
  375. return this.Control as TextBox;
  376. }
  377. }
  378. /// <summary>
  379. /// Gets or sets the editors current value
  380. /// </summary>
  381. protected decimal Value
  382. {
  383. get
  384. {
  385. if (this.UserEdit)
  386. {
  387. this.ValidateEditText();
  388. }
  389. return this.currentValue;
  390. }
  391. set
  392. {
  393. if (value != this.currentValue)
  394. {
  395. if (value < this.minimum)
  396. {
  397. value = this.maximum;
  398. }
  399. if (value > this.maximum)
  400. {
  401. value = this.maximum;
  402. }
  403. this.currentValue = value;
  404. this.UpdateEditText();
  405. }
  406. }
  407. }
  408. /// <summary>
  409. /// Gets or sets the value to increment or decrement when the up or down
  410. /// buttons are clicked
  411. /// </summary>
  412. protected decimal Increment
  413. {
  414. get
  415. {
  416. return this.increment;
  417. }
  418. set
  419. {
  420. if (value < new decimal(0))
  421. {
  422. throw new ArgumentException("increment must be greater than zero");
  423. }
  424. this.increment = value;
  425. }
  426. }
  427. /// <summary>
  428. /// Gets or sets the maximum value for the editor
  429. /// </summary>
  430. protected decimal Maximum
  431. {
  432. get
  433. {
  434. return this.maximum;
  435. }
  436. set
  437. {
  438. this.maximum = value;
  439. if (this.minimum > this.maximum)
  440. {
  441. this.minimum = this.maximum;
  442. }
  443. }
  444. }
  445. /// <summary>
  446. /// Gets or sets the minimum value for the editor
  447. /// </summary>
  448. protected decimal Minimum
  449. {
  450. get
  451. {
  452. return this.minimum;
  453. }
  454. set
  455. {
  456. this.minimum = value;
  457. if (this.minimum > this.maximum)
  458. {
  459. this.maximum = value;
  460. }
  461. }
  462. }
  463. /// <summary>
  464. /// Gets or sets the string that specifies how the editors contents
  465. /// are formatted
  466. /// </summary>
  467. protected string Format
  468. {
  469. get
  470. {
  471. return this.format;
  472. }
  473. set
  474. {
  475. if (value == null)
  476. {
  477. throw new ArgumentNullException("value");
  478. }
  479. this.format = value;
  480. this.UpdateEditText();
  481. }
  482. }
  483. /// <summary>
  484. /// Gets or sets whether the editors text is being updated
  485. /// </summary>
  486. protected bool ChangingText
  487. {
  488. get
  489. {
  490. return this.changingText;
  491. }
  492. set
  493. {
  494. this.changingText = value;
  495. }
  496. }
  497. /// <summary>
  498. /// Gets or sets whether the arrow keys should be passed to the editor
  499. /// </summary>
  500. public bool InterceptArrowKeys
  501. {
  502. get
  503. {
  504. return this.interceptArrowKeys;
  505. }
  506. set
  507. {
  508. this.interceptArrowKeys = value;
  509. }
  510. }
  511. /// <summary>
  512. /// Gets or sets whether the user has changed the editors value
  513. /// </summary>
  514. protected bool UserEdit
  515. {
  516. get
  517. {
  518. return this.userEdit;
  519. }
  520. set
  521. {
  522. this.userEdit = value;
  523. }
  524. }
  525. #endregion
  526. #region Events
  527. /// <summary>
  528. /// Handler for the editors TextBox.MouseWheel event
  529. /// </summary>
  530. /// <param name="sender">The object that raised the event</param>
  531. /// <param name="e">A MouseEventArgs that contains the event data</param>
  532. protected internal virtual void OnMouseWheel(object sender, MouseEventArgs e)
  533. {
  534. bool up = true;
  535. this.wheelDelta += e.Delta;
  536. if (Math.Abs(this.wheelDelta) >= 120)
  537. {
  538. if (this.wheelDelta < 0)
  539. {
  540. up = false;
  541. }
  542. if (up)
  543. {
  544. this.UpButton();
  545. }
  546. else
  547. {
  548. this.DownButton();
  549. }
  550. this.wheelDelta = 0;
  551. }
  552. }
  553. /// <summary>
  554. /// Handler for the editors TextBox.KeyDown event
  555. /// </summary>
  556. /// <param name="sender">The object that raised the event</param>
  557. /// <param name="e">A KeyEventArgs that contains the event data</param>
  558. protected virtual void OnTextBoxKeyDown(object sender, KeyEventArgs e)
  559. {
  560. if (this.interceptArrowKeys)
  561. {
  562. if (e.KeyData == Keys.Up)
  563. {
  564. this.UpButton();
  565. e.Handled = true;
  566. }
  567. else if (e.KeyData == Keys.Down)
  568. {
  569. this.DownButton();
  570. e.Handled = true;
  571. }
  572. }
  573. if (e.KeyCode == Keys.Return)
  574. {
  575. this.ValidateEditText();
  576. }
  577. }
  578. /// <summary>
  579. /// Handler for the editors TextBox.KeyPress event
  580. /// </summary>
  581. /// <param name="sender">The object that raised the event</param>
  582. /// <param name="e">A KeyPressEventArgs that contains the event data</param>
  583. protected virtual void OnTextBoxKeyPress(object sender, KeyPressEventArgs e)
  584. {
  585. char enter = AsciiChars.CarriageReturn;
  586. char escape = AsciiChars.Escape;
  587. char tab = AsciiChars.HorizontalTab;
  588. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat;
  589. string decimalSeparator = info.NumberDecimalSeparator;
  590. string groupSeparator = info.NumberGroupSeparator;
  591. string negativeSign = info.NegativeSign;
  592. string character = e.KeyChar.ToString();
  593. if ((!char.IsDigit(e.KeyChar) && !character.Equals(decimalSeparator) && !character.Equals(groupSeparator)) &&
  594. !character.Equals(negativeSign) && (e.KeyChar != tab))
  595. {
  596. if ((Control.ModifierKeys & (Keys.Alt | Keys.Control)) == Keys.None)
  597. {
  598. e.Handled = true;
  599. if (e.KeyChar == enter)
  600. {
  601. if (this.EditingTable != null)
  602. {
  603. this.EditingTable.StopEditing();
  604. }
  605. }
  606. else if (e.KeyChar == escape)
  607. {
  608. if (this.EditingTable != null)
  609. {
  610. this.EditingTable.CancelEditing();
  611. }
  612. }
  613. else
  614. {
  615. NativeMethods.MessageBeep(0 /*MB_OK*/);
  616. }
  617. }
  618. }
  619. }
  620. /// <summary>
  621. /// Handler for the editors TextBox.LostFocus event
  622. /// </summary>
  623. /// <param name="sender">The object that raised the event</param>
  624. /// <param name="e">An EventArgs that contains the event data</param>
  625. protected virtual void OnTextBoxLostFocus(object sender, EventArgs e)
  626. {
  627. if (this.UserEdit)
  628. {
  629. this.ValidateEditText();
  630. }
  631. if (this.EditingTable != null)
  632. {
  633. this.EditingTable.StopEditing();
  634. }
  635. }
  636. /// <summary>
  637. /// Handler for the editors buttons MouseDown event
  638. /// </summary>
  639. /// <param name="sender">The object that raised the event</param>
  640. /// <param name="e">A CellMouseEventArgs that contains the event data</param>
  641. public void OnEditorButtonMouseDown(object sender, CellMouseEventArgs e)
  642. {
  643. this.ParseEditText();
  644. if (e.Y < this.buttonBounds.Top + (this.buttonBounds.Height / 2))
  645. {
  646. this.buttonID = UpButtonID;
  647. this.UpButton();
  648. }
  649. else
  650. {
  651. this.buttonID = DownButtonID;
  652. this.DownButton();
  653. }
  654. this.StartTimer();
  655. }
  656. /// <summary>
  657. /// Handler for the editors buttons MouseUp event
  658. /// </summary>
  659. /// <param name="sender">The object that raised the event</param>
  660. /// <param name="e">A CellMouseEventArgs that contains the event data</param>
  661. public void OnEditorButtonMouseUp(object sender, CellMouseEventArgs e)
  662. {
  663. this.StopTimer();
  664. this.buttonID = 0;
  665. }
  666. /// <summary>
  667. /// Handler for the editors Timer event
  668. /// </summary>
  669. /// <param name="sender">The object that raised the event</param>
  670. /// <param name="e">An EventArgs that contains the event data</param>
  671. private void TimerHandler(object sender, EventArgs e)
  672. {
  673. if (buttonID == 0)
  674. {
  675. this.StopTimer();
  676. return;
  677. }
  678. if (buttonID == UpButtonID)
  679. {
  680. this.UpButton();
  681. }
  682. else
  683. {
  684. this.DownButton();
  685. }
  686. this.interval *= 7;
  687. this.interval /= 10;
  688. if (this.interval < 1)
  689. {
  690. this.interval = 1;
  691. }
  692. this.timer.Interval = this.interval;
  693. }
  694. #endregion
  695. }
  696. }