DrawCommand.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:3k
源码类别:

状态条

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. namespace UtilityLibrary.Menus
  4. {
  5. internal class DrawCommand
  6. {
  7. #region Class Variables
  8. protected int row;
  9. protected int col;
  10. protected char  mnemonic;
  11. protected bool  enabled;
  12. protected bool  subMenu;
  13. protected bool  expansion;
  14. protected bool  separator;
  15. protected bool  vertSeparator;
  16. protected bool  chevron;
  17. protected Rectangle drawRect;
  18. protected MenuCommand menuCommand;
  19. #endregion
  20. #region Constructors
  21. public DrawCommand(Rectangle drawRect)
  22. {
  23. row = -1;
  24. col = -1;
  25.  mnemonic = '0';
  26.  enabled = true;
  27.  subMenu = false;
  28.  expansion = false;
  29.  separator = false;
  30.  vertSeparator = false;
  31.  chevron = true;
  32. this.drawRect = drawRect;
  33. menuCommand = null;
  34. }
  35. public DrawCommand(Rectangle drawRect, bool expansion)
  36. {
  37. row = -1;
  38. col = -1;
  39.  mnemonic = '0';
  40.  enabled = true;
  41.  subMenu = false;
  42.  expansion = expansion;
  43.  separator = !expansion;
  44.  vertSeparator = !expansion;
  45.  chevron = false;
  46. this.drawRect = drawRect;
  47. menuCommand = null;
  48. }
  49. public DrawCommand(MenuCommand command, Rectangle drawRect)
  50. {
  51. InternalConstruct(command, drawRect, -1, -1);
  52. }
  53. public DrawCommand(MenuCommand command, Rectangle drawRect, int row, int col)
  54. {
  55. InternalConstruct(command, drawRect, row, col);
  56. }
  57. public void InternalConstruct(MenuCommand command, Rectangle drawRect, int row, int col)
  58. {
  59. row = row;
  60. col = col;
  61.  enabled = command.Enabled;
  62.  expansion = false;
  63.  vertSeparator = false;
  64. this.drawRect = drawRect;
  65. menuCommand = command;
  66.  chevron = false;
  67. // Is this MenuCommand a separator?
  68.  separator = (menuCommand.Text == "-");
  69. // Does this MenuCommand contain a submenu?
  70.  subMenu = (menuCommand.MenuCommands.Count > 0);
  71. // Find position of first mnemonic character
  72. if ( command.Text == null || command.Text == string.Empty )
  73. return;
  74. int position = command.Text.IndexOf('&');
  75. // Did we find a mnemonic indicator?
  76. if (position != -1)
  77. {
  78. // Must be a character after the indicator
  79. if (position < (command.Text.Length - 1))
  80. {
  81. // Remember the character
  82.  mnemonic = char.ToUpper(command.Text[position + 1]);
  83. }
  84. }
  85. }
  86. #endregion
  87. #region Properties
  88. public Rectangle DrawRect
  89. {
  90. get { return drawRect; }
  91. set { drawRect = value; }
  92. }
  93. public MenuCommand MenuCommand
  94. {
  95. get { return menuCommand; }
  96. }
  97. public bool Separator
  98. {
  99. get { return  separator; }
  100. }
  101. public bool VerticalSeparator
  102. {
  103. get { return  vertSeparator; }
  104. }
  105. public bool Expansion
  106. {
  107. get { return  expansion; }
  108. }
  109. public bool SubMenu
  110. {
  111. get { return  subMenu; }
  112. }
  113. public char Mnemonic
  114. {
  115. get { return  mnemonic; }
  116. }
  117. public bool Enabled
  118. {
  119. get { return  enabled; }
  120. }
  121. public int Row
  122. {
  123. get { return row; }
  124. }
  125. public int Col
  126. {
  127. get { return col; }
  128. }
  129. public bool Chevron
  130. {
  131. get { return  chevron; }
  132. }
  133. #endregion 
  134. }
  135. }