DrawCommand.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:3k
- using System;
- using System.Drawing;
- namespace UtilityLibrary.Menus
- {
- internal class DrawCommand
- {
- #region Class Variables
- protected int row;
- protected int col;
- protected char mnemonic;
- protected bool enabled;
- protected bool subMenu;
- protected bool expansion;
- protected bool separator;
- protected bool vertSeparator;
- protected bool chevron;
- protected Rectangle drawRect;
- protected MenuCommand menuCommand;
- #endregion
- #region Constructors
- public DrawCommand(Rectangle drawRect)
- {
- row = -1;
- col = -1;
- mnemonic = '0';
- enabled = true;
- subMenu = false;
- expansion = false;
- separator = false;
- vertSeparator = false;
- chevron = true;
- this.drawRect = drawRect;
- menuCommand = null;
- }
- public DrawCommand(Rectangle drawRect, bool expansion)
- {
- row = -1;
- col = -1;
- mnemonic = '0';
- enabled = true;
- subMenu = false;
- expansion = expansion;
- separator = !expansion;
- vertSeparator = !expansion;
- chevron = false;
- this.drawRect = drawRect;
- menuCommand = null;
- }
- public DrawCommand(MenuCommand command, Rectangle drawRect)
- {
- InternalConstruct(command, drawRect, -1, -1);
- }
- public DrawCommand(MenuCommand command, Rectangle drawRect, int row, int col)
- {
- InternalConstruct(command, drawRect, row, col);
- }
- public void InternalConstruct(MenuCommand command, Rectangle drawRect, int row, int col)
- {
- row = row;
- col = col;
- enabled = command.Enabled;
- expansion = false;
- vertSeparator = false;
- this.drawRect = drawRect;
- menuCommand = command;
- chevron = false;
- // Is this MenuCommand a separator?
- separator = (menuCommand.Text == "-");
- // Does this MenuCommand contain a submenu?
- subMenu = (menuCommand.MenuCommands.Count > 0);
- // Find position of first mnemonic character
- if ( command.Text == null || command.Text == string.Empty )
- return;
- int position = command.Text.IndexOf('&');
- // Did we find a mnemonic indicator?
- if (position != -1)
- {
- // Must be a character after the indicator
- if (position < (command.Text.Length - 1))
- {
- // Remember the character
- mnemonic = char.ToUpper(command.Text[position + 1]);
- }
- }
- }
- #endregion
-
- #region Properties
- public Rectangle DrawRect
- {
- get { return drawRect; }
- set { drawRect = value; }
- }
- public MenuCommand MenuCommand
- {
- get { return menuCommand; }
- }
- public bool Separator
- {
- get { return separator; }
- }
- public bool VerticalSeparator
- {
- get { return vertSeparator; }
- }
- public bool Expansion
- {
- get { return expansion; }
- }
- public bool SubMenu
- {
- get { return subMenu; }
- }
- public char Mnemonic
- {
- get { return mnemonic; }
- }
- public bool Enabled
- {
- get { return enabled; }
- }
- public int Row
- {
- get { return row; }
- }
- public int Col
- {
- get { return col; }
- }
- public bool Chevron
- {
- get { return chevron; }
- }
- #endregion
- }
- }