Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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?

Edited by Phylum
Posted (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:

 

    //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:

 

     [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:

 

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

 

The SuperLabel control just inherits from the BaseControl.

 

I hope this helps

Edited by Phylum

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...