Properties not persisting at design time.

S

Steve Barker

Guys

Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time

I have written a control by inheriting from the Button control. I am trying to add a feature whereby the control changes to a different color when the mouse floats over it, or when the button has the focus. The color changing works if the 'LightColor' is set at runtime in code. However, if I draw the control on a form at design time, change the 'LightColor' property in the Property viewing window, save the form, then close and reopen the form, the property value (as seen in the window) goes back to the default value for the control. It's driving me mad, since I can't see what I've done wrong.

Here is the code for my control

-------------------------------------------------------------------------------
using System
using System.Collections
using System.ComponentModel
using System.Drawing
using System.Data
using System.Windows.Forms

namespace HCS.Components.Control

public class LightButton : Butto

#region Field

private System.ComponentModel.Container components = null
private Color mBackColor
private Color mLightColor
private bool mIsMouseOver

#endregio

#region Constructo

public LightButton(

// This call is required by the Windows.Forms Form Designer
InitializeComponent()

mBackColor = base.BackColor
mLightColor = base.BackColor



#endregio

#region Clean Up Cod

/// <summary>
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing

if( disposing

if(components != null

components.Dispose()


base.Dispose( disposing )


#endregio

#region Component Designer generated cod
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(

components = new System.ComponentModel.Container()

#endregio

#region Propertie

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
[DefaultValue(typeof(System.Drawing.Color), "System.Drawing.SystemColors.Window")
public new Color BackColo

ge

return mBackColor

se

mBackColor = value
SetColour();





[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
[DefaultValue(typeof(bool), "true")
public new bool Enable

ge

return base.Enabled

se

base.Enabled = value
SetColour()




[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
[DefaultValue(typeof(System.Drawing.Color), "System.Drawing.SystemColors.Window")
public Color LightColo

ge

return mLightColor

se

mLightColor = value
SetColour()




#endregio

#region Protected Override Method

protected override void OnMouseEnter(EventArgs e

base.OnMouseEnter (e)
mIsMouseOver = true
SetColour()



protected override void OnMouseLeave(EventArgs e

base.OnMouseLeave (e)
mIsMouseOver = false
SetColour()




protected override void OnGotFocus(EventArgs e

base.OnGotFocus (e)
SetColour()



protected override void OnLostFocus(EventArgs e

base.OnLostFocus (e)
SetColour()




#endregio

#region Private Method

private void SetColour(

if(mIsMouseOver || base.Focused

base.BackColor = mLightColor

els

base.BackColor = mBackColor




#endregio


-------------------------------------------------------------------------------

Please help - I'm going insane!

Thanks in advance

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top