?
Solved

WIndows Form Inheritance

Posted on 2008-10-21
11
Medium Priority
?
836 Views
Last Modified: 2013-12-17
Experts,

Is Windows Forms inheritance a good idea?  I'm experimenting with it, but the derived forms always have locked controls.  Ideas?
0
Comment
Question by:NigelRocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 2000 total points
ID: 22774240
You can set the controls to not be locked.  In the base form change the controls Modifiers property from Private to whichever setting best suits your needs. Public would mean that every form that inherited from it would have the control and could have their own code
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22774241
Oh and to answer your other question; yes it is a very good idea.  It will keep all forms consistent and save time/effort.
0
 
LVL 1

Author Closing Comment

by:NigelRocks
ID: 31508643
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.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 1

Author Comment

by:NigelRocks
ID: 22775711
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?
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22776295
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....
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22776404
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

0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22776584
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?
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22779539
I'm not seeing a "modifier" property on any of my forms.
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22783934
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 :)
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22788485
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.
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 22801637
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?
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question