HelpfulHighlighterRibbon.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /***
  2. * Project: Helpful Highlighter Excel Add-In
  3. * Component: Options ribbon menu group
  4. * Author: Todd Boyd
  5. * Date: 2010/10/26
  6. * Description:
  7. *
  8. * The options for Helpful Highlighter are found in the Helpful Highlighter group on the Add-Ins ribbon tab.
  9. * Helpful Highlighter saves its options so that they will persist between Excel sessions.
  10. *
  11. * Enable:
  12. * If this unchecked, the Add-In will not highlight/cache anything. When it is unchecked, any current
  13. * highlighting will be removed.
  14. * Preserve color:
  15. * If this is unchecked, the background color of the highlighted cells will not be preserved, and
  16. * will be reset to XlColor.XlNothing when a new area is selected. Even if Preserve Color is unchecked,
  17. * the color buffer will be restored on the next selection change if it is not already empty.
  18. * Choose color:
  19. * Opens a color dialog to allow the user to choose the color that will be used when highlighting
  20. * cells.
  21. ***/
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using System.Text;
  26. using Microsoft.Office.Tools.Ribbon;
  27. namespace HelpfulHighlighter
  28. {
  29. public partial class HelpfulHighlighterRibbon : OfficeRibbon
  30. {
  31. public HelpfulHighlighter.ThisAddIn addin = null;
  32. public HelpfulHighlighterRibbon()
  33. {
  34. InitializeComponent();
  35. }
  36. // get currently-selected highlighting color
  37. public int GetColor()
  38. {
  39. return System.Drawing.ColorTranslator.ToOle(clrHighlight.Color);
  40. }
  41. // startup process
  42. private void HelpfulHighlighterRibbon_Load(object sender, RibbonUIEventArgs e)
  43. {
  44. // load settings and affect ribbon
  45. clrHighlight.Color = System.Drawing.ColorTranslator.FromOle((int)HelpfulHighlighter.Properties.Settings.Default.color);
  46. this.chkPreserve.Checked = (bool)HelpfulHighlighter.Properties.Settings.Default.preserve;
  47. this.chkEnabled.Checked = (bool)HelpfulHighlighter.Properties.Settings.Default.enabled;
  48. }
  49. private void chkEnabled_Click(object sender, RibbonControlEventArgs e)
  50. {
  51. // set value and clear highlighting
  52. if(! this.chkEnabled.Checked)
  53. {
  54. HelpfulHighlighter.Properties.Settings.Default.enabled = false;
  55. this.addin.CleanUp();
  56. }
  57. // set value
  58. else
  59. HelpfulHighlighter.Properties.Settings.Default.enabled = true;
  60. HelpfulHighlighter.Properties.Settings.Default.Save();
  61. }
  62. private void btnColor_Click(object sender, RibbonControlEventArgs e)
  63. {
  64. // use color dialog to determine selection
  65. System.Windows.Forms.DialogResult result = clrHighlight.ShowDialog();
  66. if(result != System.Windows.Forms.DialogResult.OK)
  67. return;
  68. // set value
  69. HelpfulHighlighter.Properties.Settings.Default.color = System.Drawing.ColorTranslator.ToOle(clrHighlight.Color);
  70. HelpfulHighlighter.Properties.Settings.Default.Save();
  71. }
  72. private void chkPreserve_Click(object sender, RibbonControlEventArgs e)
  73. {
  74. // clear highlighting if preserve disabled
  75. if (! this.chkPreserve.Checked)
  76. this.addin.CleanUp();
  77. // set value
  78. HelpfulHighlighter.Properties.Settings.Default.preserve = this.chkPreserve.Checked;
  79. HelpfulHighlighter.Properties.Settings.Default.Save();
  80. }
  81. }
  82. }