internal void Attach(TAction a, Component o, bool designMode) { Debug.Assert(o != null && a != null); _component = o; _owner = a; Debug.Assert(_owner.Parent != null); // Text _text = o.GetType().GetProperty("Text"); if (_text != null && (!_text.CanRead || !_text.CanWrite) && (_text.PropertyType == typeof(string))) { // we must be able to read and write a boolean property _text = null; } Text = _owner.Text; // Enabled _enabled = o.GetType().GetProperty("Enabled"); if (_enabled != null && (!_enabled.CanRead || !_enabled.CanWrite) && (_enabled.PropertyType == typeof(bool))) { // we must be able to read and write a boolean property _enabled = null; } Enabled = _owner.Enabled; // Checked #if HasToolBar // special case of a toolbarButton if (_component is ToolBarButton) { _checked = o.GetType().GetProperty("Pushed"); Debug.Assert(_checked != null && _checked.CanRead && _checked.CanWrite && (_checked.PropertyType == typeof(bool))); } else #endif { _checked = o.GetType().GetProperty("Checked"); if (_checked != null && (!_checked.CanRead || !_checked.CanWrite) && (_checked.PropertyType == typeof(bool))) { // we must be able to read and write a boolean property _checked = null; } } Checked = _owner.Checked; // Visible _visible = o.GetType().GetProperty("Visible"); if (_visible != null && (!_visible.CanRead || !_visible.CanWrite) && (_visible.PropertyType == typeof(bool))) { // we must be able to read and write a boolean property _visible = null; } Visible = _owner.Visible; // Shortcut _shortcut = o.GetType().GetProperty("Shortcut"); if (_shortcut != null && (!_shortcut.CanRead || !_shortcut.CanWrite) && (_shortcut.PropertyType == typeof(Shortcut))) { // we must be able to read and write a shortcut property _shortcut = null; } Shortcut = _owner.Shortcut; // ShortcutKeys _shortcutKeys = o.GetType().GetProperty("ShortcutKeys"); if (_shortcutKeys != null && (!_shortcutKeys.CanRead || !_shortcutKeys.CanWrite) && (_shortcutKeys.PropertyType == typeof(Keys))) { // we must be able to read and write a shortcutKey property _shortcutKeys = null; } ShortcutKeys = _owner.ShortcutKeys; // ImageList // don't handle toolbarButtons here #if HasToolBar if (!(_component is ToolBarButton)) #endif { _imageList = o.GetType().GetProperty("ImageList"); if (_imageList != null && (!_imageList.CanRead || !_imageList.CanWrite) && (_imageList.PropertyType == typeof(ImageList))) { // we must be able to read and write an ImageList property _imageList = null; } } ImageList = _owner.Parent.ImageList; // ImageIndex _imageIndex = o.GetType().GetProperty("ImageIndex"); if (_imageIndex != null && (!_imageIndex.CanRead || !_imageIndex.CanWrite) && (_imageIndex.PropertyType == typeof(int))) { // we must be able to read and write an integer property _imageIndex = null; } ImageIndex = _owner.ImageIndex; // Hint Hint = _owner.Hint; // click if (!designMode) { #if HasToolBar // special case of a toolbarButton if (_component is ToolBarButton) { ToolBar tb = ((ToolBarButton)_component).Parent; if (tb != null) { tb.ButtonClick += new ToolBarButtonClickEventHandler(OnToolbarClick); _click = true; } } else #endif { EventInfo e = o.GetType().GetEvent("Click"); if (e != null && e.EventHandlerType == typeof(EventHandler)) { e.AddEventHandler(_component, new EventHandler(_owner.OnExecute)); _click = true; } } } // Dispose Debug.Assert(_owner.Parent != null); _component.Disposed += new EventHandler(_owner.Parent.OnComponentDisposed); }