DXMenuItem.cs
Upload User: lh8511
Upload Date: 2013-01-28
Package Size: 7353k
Code Size: 4k
Development Platform:

Visual C++

  1. namespace DevExpress.Utils.Menu
  2. {
  3.     using System;
  4.     using System.Drawing;
  5.     using System.Runtime.CompilerServices;
  6.     using System.Windows.Forms;
  7.     public class DXMenuItem : IDisposable
  8.     {
  9.         private bool beginGroup;
  10.         private string caption;
  11.         private DXMenuItemCollection collection;
  12.         private bool enabled;
  13.         private System.Drawing.Image image;
  14.         private System.Windows.Forms.Shortcut shortcut;
  15.         private object tag;
  16.         private bool visible;
  17.         public event EventHandler Click;
  18.         public DXMenuItem() : this("")
  19.         {
  20.         }
  21.         public DXMenuItem(string caption) : this(caption, null)
  22.         {
  23.         }
  24.         public DXMenuItem(string caption, EventHandler click) : this(caption, click, null)
  25.         {
  26.         }
  27.         public DXMenuItem(string caption, EventHandler click, System.Drawing.Image image)
  28.         {
  29.             this.enabled = true;
  30.             this.visible = true;
  31.             this.Click = click;
  32.             this.caption = caption;
  33.             this.image = image;
  34.         }
  35.         public virtual void Dispose()
  36.         {
  37.             this.Click = null;
  38.         }
  39.         public void GenerateClickEvent()
  40.         {
  41.             this.OnClick();
  42.         }
  43.         protected virtual void OnChanged()
  44.         {
  45.             if (this.Collection != null)
  46.             {
  47.                 this.Collection.OnMenuItemChanged(this);
  48.             }
  49.         }
  50.         protected virtual void OnClick()
  51.         {
  52.             if (this.Click != null)
  53.             {
  54.                 this.Click(this, EventArgs.Empty);
  55.             }
  56.         }
  57.         protected internal void SetCollection(DXMenuItemCollection collection)
  58.         {
  59.             this.collection = collection;
  60.         }
  61.         public bool BeginGroup
  62.         {
  63.             get
  64.             {
  65.                 return this.beginGroup;
  66.             }
  67.             set
  68.             {
  69.                 if (this.BeginGroup != value)
  70.                 {
  71.                     this.beginGroup = value;
  72.                     this.OnChanged();
  73.                 }
  74.             }
  75.         }
  76.         public string Caption
  77.         {
  78.             get
  79.             {
  80.                 return this.caption;
  81.             }
  82.             set
  83.             {
  84.                 if (this.Caption != value)
  85.                 {
  86.                     this.caption = value;
  87.                     this.OnChanged();
  88.                 }
  89.             }
  90.         }
  91.         public DXMenuItemCollection Collection
  92.         {
  93.             get
  94.             {
  95.                 return this.collection;
  96.             }
  97.         }
  98.         public bool Enabled
  99.         {
  100.             get
  101.             {
  102.                 return this.enabled;
  103.             }
  104.             set
  105.             {
  106.                 if (this.Enabled != value)
  107.                 {
  108.                     this.enabled = value;
  109.                     this.OnChanged();
  110.                 }
  111.             }
  112.         }
  113.         public System.Drawing.Image Image
  114.         {
  115.             get
  116.             {
  117.                 return this.image;
  118.             }
  119.             set
  120.             {
  121.                 if (this.Image != value)
  122.                 {
  123.                     this.image = value;
  124.                     this.OnChanged();
  125.                 }
  126.             }
  127.         }
  128.         public System.Windows.Forms.Shortcut Shortcut
  129.         {
  130.             get
  131.             {
  132.                 return this.shortcut;
  133.             }
  134.             set
  135.             {
  136.                 if (this.Shortcut != value)
  137.                 {
  138.                     this.shortcut = value;
  139.                     this.OnChanged();
  140.                 }
  141.             }
  142.         }
  143.         public object Tag
  144.         {
  145.             get
  146.             {
  147.                 return this.tag;
  148.             }
  149.             set
  150.             {
  151.                 if (this.Tag != value)
  152.                 {
  153.                     this.tag = value;
  154.                     this.OnChanged();
  155.                 }
  156.             }
  157.         }
  158.         public bool Visible
  159.         {
  160.             get
  161.             {
  162.                 return this.visible;
  163.             }
  164.             set
  165.             {
  166.                 if (this.Visible != value)
  167.                 {
  168.                     this.visible = value;
  169.                     this.OnChanged();
  170.                 }
  171.             }
  172.         }
  173.     }
  174. }