Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
685
How to extend Control and change some property default values for Designer generated code
posted

I'm trying to extend some controls for usage on a touch screen.
So I need to increase size of some parts of the control.

Let's take as an example the UltraCheckEditor.
I've attached a sample project with a UltraCheckEditorTS class that inherits from UltraCheckEditor.

Here is an excerpt of the UltraCheckEditorTS class (I'm using some helper class from the sample: to generate the GlyphInfo)

public class UltraCheckEditorTS : UltraCheckEditor
    {

        private Appearance m_defaultAppearance;
        private GlyphInfoBase m_defaultGlyphInfo;
       
        public UltraCheckEditorTS()
        {
            m_defaultAppearance = new Appearance("UltraCheckEditorTSDefault", 0);
            m_defaultAppearance.BackColor = Color.LightCyan;
            m_defaultAppearance.FontData.Bold = DefaultableBoolean.True;
            m_defaultAppearance.FontData.SizeInPoints = 15;
            m_defaultAppearance.FontData.Name = "Microsoft Sans Serif";

            CheckBoxGlyphSettings glyphSettings = new CheckBoxGlyphSettings();
            glyphSettings.BaseColor = Color.Black;
            glyphSettings.Size = new Size(30, 30);
            m_defaultGlyphInfo = glyphSettings.ToGlyphInfo();
           
            this.Appearance = m_defaultAppearance;
            this.GlyphInfo = m_defaultGlyphInfo;
        }
    }
   
Great! this is working well, my customization are applied to the control when I drag&drop on a form.
However... in the form hosting my control, the designer has serialized my Appearance and GlyphInfo customization:

private void InitializeComponent()
        {
            ...
            //
            // ultraCheckEditorTS1
            //
            appearance1.BackColor = System.Drawing.Color.LightCyan;
            appearance1.FontData.BoldAsString = "True";
            appearance1.FontData.Name = "Microsoft Sans Serif";
            appearance1.FontData.SizeInPoints = 15F;
            this.ultraCheckEditorTS1.Appearance = appearance1;
            this.ultraCheckEditorTS1.BackColor = System.Drawing.Color.LightCyan;
            this.ultraCheckEditorTS1.GlyphInfo = new Infragistics.Win.CheckBoxImageGlyphInfo(((System.Drawing.Bitmap)(resources.GetObject("ultraCheckEditorTS1.GlyphInfo"))), "Custom checkbox glyphs");
            this.ultraCheckEditorTS1.Location = new System.Drawing.Point(54, 40);
            this.ultraCheckEditorTS1.Name = "ultraCheckEditorTS1";
            this.ultraCheckEditorTS1.Size = new System.Drawing.Size(120, 20);
            this.ultraCheckEditorTS1.TabIndex = 0;
            this.ultraCheckEditorTS1.Text = "ultraCheckEditorTS1";
            ...
        }
   
Which means future updates made to the class UltraCheckEditorTS will not be reflected into this forms...
Ex; If I change the FontData.SizeInPoints to 14, the form will still set this value to 15 in the designer generated code.

What is the correct way to override some default control settings, and make the hosting form designer serialize only if the value are different from my new custom control default values ?

ControlPropertyDefaultValue.zip
  • 5
    Suggested Answer
    posted

    Hi we have the same problem as you in our project. We customised some controls (TextEditor, Checkbox, Label and Combo) and the only way we found to update the new properties was adding a method after the initialisation. This way is also not so optimal, because we should call it for each control element build in a form!

    Updating the default properties in the generated code can only be done by deleting the one we change. what is a big problem because we have a project with more than 100 Forms.