home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / CSharp / Applications / Custom Control / ActionControl.cs < prev    next >
Encoding:
Text File  |  2004-10-22  |  5.7 KB  |  190 lines

  1. /*********************************************************
  2. Simple Action Component for MenuItem
  3. Example submitted by Chua Chee Wee, Singapore
  4.  
  5. To use, compile.
  6. Install into the Tool Palette using
  7. 1) Menu Components | Installed .Net Components
  8. 2) Select an Assembly: Action.dll
  9. 3) Then open the ActionDemo.bdsproj.
  10. 4) Start changing the Visible | Enabled | Text properties
  11.    of the action1 item and see the associated component
  12.    change its properties correspondingly!
  13.  
  14. Current issues:
  15. 1. Do not set ComponentLink to point to itself, i.e.:
  16. if you have an Action named action1, do not set its
  17. ComponentLink to action1, otherwise, you'll hang the IDE.
  18.  
  19. 2. Do not point ComponentLink to a top level MenuItem.
  20.  
  21. **********************************************************/
  22. using System;
  23. using System.Collections;
  24. using System.ComponentModel;
  25. using System.Drawing;
  26. using System.Data;
  27. using System.Windows.Forms;
  28. using System.Reflection;
  29.  
  30. [assembly:
  31.  AssemblyVersion("1.0.0.*"),
  32.  AssemblyCompany(""),
  33.  AssemblyTitle("MenuItem Action Demo"),
  34.  AssemblyDescription("A simple custom control component"),
  35.  AssemblyCopyright(""),
  36.  AssemblyTrademark("Some example trademark"),
  37.  AssemblyInformationalVersion(""),
  38.  AssemblyProduct("")
  39. ]
  40. // Browse the above attributes using Borland Reflection
  41. namespace ActionControl
  42. {
  43.     /// <summary>
  44.     /// Summary description for TAction.
  45.     /// </summary>
  46.     public class Action : System.ComponentModel.Component
  47.     {
  48.         /// <summary>
  49.         /// Required designer variable.
  50.         /// </summary>
  51.         private System.ComponentModel.Container components = null;
  52.  
  53.         public Action()
  54.         {
  55.             // This call is required by the Windows.Forms Designer.
  56.             InitializeComponent();
  57.  
  58.             // TODO: Add any initialization after the InitForm call
  59.  
  60.         }
  61.  
  62.         /// <summary>
  63.         /// Clean up any resources being used.
  64.         /// </summary>
  65.         protected override void Dispose(bool disposing)
  66.         {
  67.             if (disposing)
  68.             {
  69.                 if (components != null)
  70.                     components.Dispose();
  71.             }
  72.             base.Dispose(disposing);
  73.         }
  74.  
  75.         #region Component Designer generated code
  76.         /// <summary>
  77.         /// Required method for Designer support - do not modify
  78.         /// the contents of this method with the code editor.
  79.         /// </summary>
  80.         private void InitializeComponent()
  81.         {
  82.             components = new System.ComponentModel.Container();
  83.         }
  84.         #endregion
  85.  
  86.         private System.ComponentModel.Component _ComponentLink=null;
  87.  
  88.         [Browsable(true),
  89.          Category("Misc"),
  90.          Description("Links to the specified component, allowing you to change it's Text, Visible or Enabled properties.")]
  91.         public System.ComponentModel.Component ComponentLink {
  92.             get {
  93.                 return _ComponentLink;
  94.             }
  95.             set {
  96.                  if (value==this)
  97.                    throw new Exception("ComponentLink cannot be set to itself!");
  98.                  if (value is Action)
  99.                    throw new Exception("ComponentLink cannot be another instance of the same type!");
  100.                  if ((value!=null) && (!(value is MenuItem)))
  101.                    throw new Exception("Unsupported component class: "+_ComponentLink.ToString());
  102.                  _ComponentLink = value;
  103.             }
  104.  
  105.         }
  106.  
  107.         [Browsable(true),
  108.          Category("Behaviour"),
  109.          Description("Change the ComponentLink's Enabled property to the specified value")]
  110.         public bool Enabled {
  111.             get {
  112.                 if (_ComponentLink is MenuItem)
  113.                     return ((MenuItem)_ComponentLink).Enabled;
  114.                 if (_ComponentLink != null)
  115.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString()); else
  116.                     return false;
  117.             }
  118.             set {
  119.                 if (_ComponentLink is MenuItem)
  120.                     ((MenuItem)_ComponentLink).Enabled = value; else
  121.                 if (_ComponentLink != null)
  122.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString());
  123.             }
  124.         }
  125.  
  126.         [Browsable(true),
  127.          Category("Behaviour"),
  128.          Description("Change the ComponentLink's Checked property to the specified value")]
  129.         public bool Checked {
  130.             get {
  131.                 if (_ComponentLink is MenuItem)
  132.                     return ((MenuItem)_ComponentLink).Checked; else
  133.                 if (_ComponentLink != null)
  134.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString()); else
  135.                     return false;
  136.             }
  137.             set {
  138.                 if (_ComponentLink is MenuItem)
  139.                     ((MenuItem)_ComponentLink).Checked = value; else
  140.                 if (_ComponentLink != null)
  141.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString());
  142.             }
  143.         }
  144.  
  145.         [Browsable(true),
  146.          Category("Appearance"),
  147.          Description("Change the ComponentLink's Text property to the specified value")]
  148.         public string Text {
  149.             get {
  150.                  if (_ComponentLink is MenuItem)
  151.                     return ((MenuItem)_ComponentLink).Text; else
  152.                  if (_ComponentLink != null)
  153.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString()); else
  154.                  return "";
  155.             }
  156.             set {
  157.                 if (_ComponentLink is MenuItem)
  158.                     ((MenuItem)_ComponentLink).Text = value; else
  159.                 if (_ComponentLink != null)
  160.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString());
  161.             }
  162.         }
  163.  
  164.         [Browsable(true),
  165.          Category("Appearance"),
  166.          Description("Change the ComponentLink's Visible property to the specified value")]
  167.         public bool Visible {
  168.             get {
  169.                 if (_ComponentLink is MenuItem)
  170.                     return ((MenuItem)_ComponentLink).Visible; else
  171.                 if (_ComponentLink != null)
  172.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString()); else
  173.                 return false;
  174.             }
  175.             set {
  176.                  if (_ComponentLink is MenuItem)
  177.                     ((MenuItem)_ComponentLink).Checked = value; else
  178.                  if (_ComponentLink != null)
  179.                     throw new Exception("Unsupported component class: "+_ComponentLink.ToString());
  180.             }
  181.         }
  182.  
  183.         public override string ToString() {
  184.             return "Setting ComponentLink to this is not supported!";
  185.         }
  186.  
  187.  
  188.     }
  189. }
  190.