Custom Control

Phylum

Centurion
Joined
Jun 20, 2003
Messages
105
Location
Canada
Okay, this may sound a little complex but, it's not really... I swear!

1. I have created a custom control

2. The control contains a property that is a class

3. I created a TypeConverter to persist the class info (basically it writes down the properties info in the windows form designer generated code)

4. The TypeConverter is a ExpandableObjectConverter which basically means on the property grid for the CONTROL the class shows up like Font or Size

5. Whenever you change a property of the CLASS it raises an event. The CONTROL handles the event by Invalidating itself (forcing a redraw).

*** I have attached an image of what I am talking about. ***

The class contains visual properties for the control, for instance ForeColor. If I change the forecolor it should fire the event and the control should handle the event by redrawing itself at design time... the problem is it does not.

Anyone know of a solution?
 

Attachments

Last edited:
Okay here is hopefully a better explanation. The code is divided into 3 parts: the WinAppearance class, the BaseControl and my SuperLabel Control.

This is the event that is fired if any of the properties of the CLASS change:

Code:
     //Delegate declaration
      public delegate void AppearanceChangedEventHandler(object sender, System.EventArgs e); 

      //Event declaration
      public event AppearanceChangedEventHandler AppearanceChanged; 

      //The protected OnColumnAdded method raises the event by invoking the delegates. 
      //The sender is always the current instance of the class ("this" in C#, "Me" in VB)
      protected virtual void OnAppearanceChanged(System.EventArgs e) 
      { 
        
         if (AppearanceChanged != null) 
         { 
            AppearanceChanged(this, e); 
         } 
      
      }

This is the code in the BaseControl that adds the WinAppearance class as a property:

Code:
      [Description("The appearance of the control"),
      Browsable(true),
      RefreshProperties(RefreshProperties.Repaint),
      Category("Appearance")]
      public WinAppearance Appearance
      {
         
         get
         {
            return _appearance;
         }

         set
         {
            _appearance = value;
            this.Invalidate();
         }

      }

Here is the code for the BaseControl that handles whenever the AppearanceChanged event (which the WinAppearance class raises) gets fired:

Code:
      private void _appearance_AppearanceChanged(object sender, EventArgs e)
      {
         this.Invalidate();
      }

The SuperLabel control just inherits from the BaseControl.

I hope this helps
 
Last edited:
Back
Top