Link to home
Start Free TrialLog in
Avatar of NigelRocks
NigelRocks

asked on

WIndows Form Inheritance

Experts,

Is Windows Forms inheritance a good idea?  I'm experimenting with it, but the derived forms always have locked controls.  Ideas?
ASKER CERTIFIED SOLUTION
Avatar of angus_young_acdc
angus_young_acdc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh and to answer your other question; yes it is a very good idea.  It will keep all forms consistent and save time/effort.
Avatar of NigelRocks
NigelRocks

ASKER

Angus,

Your technical skills match your awesome guitar playing.  Tell Malcolm I don't want to see Phil Rudd leave the band again.  Don't make me come down there.
I spoke too soon, Angus.  Overwhelmed by encountering your rock 'n' roll greatness, I didn't test your solution enough.  I still have locked controls.  Do I need to talk to Brian Johnson?
Haha that made me laugh, certainly a good way to brighten up an otherwise dull day.

Are you sure you are changing all of your controls?  Everything in the form you inherit from has to be changed, otherwise it is locked out.  Although that's handy for certain ones (eg an exit button) which won't change.

For those about to Rock....
I've attached all the code for the parent form.  I still don't see where the problem is.
namespace UI_Inheritance_Test
{
    public partial class Parent_Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        public System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        public void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(35, 19);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(88, 50);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(57, 107);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(143, 21);
            this.comboBox1.TabIndex = 1;
            this.comboBox1.Text = "Parent Form";
            // 
            // Parent_Form
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.button1);
            this.Name = "Parent_Form";
            this.Text = "Parent Form";
            this.Load += new System.EventHandler(this.Parent_Form_Load);
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        public System.Windows.Forms.Button button1;
        public System.Windows.Forms.ComboBox comboBox1;
    }
}

Open in new window

Are you setting the Modifier property via the Design view for the form?  And have you double checked that it is not set to Private?
I'm not seeing a "modifier" property on any of my forms.
Its not on the form, it is on the individual objects.  So you would select each button, combobox etc and change its Modifier.  Best way is just to highlight them all and do it, saves time :)
I understand the part about the individual objects and not the form.  The two objects in the parent form are listed as follows:

        public System.Windows.Forms.Button button1;
        public System.Windows.Forms.ComboBox comboBox1;

Yet, they are still locked in the the second-level form.  I tried the "protected" keyword, but got the same results.
Some people say that this problem with the locked controls is a known bug and that they get around it by writing user controls.  Anyone else?