Phylum Posted November 5, 2004 Posted November 5, 2004 (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 November 5, 2004 by Phylum Quote
Administrators PlausiblyDamp Posted November 5, 2004 Administrators Posted November 5, 2004 Any chance of posting the relevant code as well? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Phylum Posted November 8, 2004 Author Posted November 8, 2004 (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 November 8, 2004 by Phylum Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.