G
Gregory Persson
I am experiencing a weird error using Visual Inheritence when setting
property values in a base form.
I have 3 forms inheriting from each other in a chain:
Form1 -> Form2 -> Form3
Form1 looks like this:
public class Form1 : Form
{
private Control ctrl;
public Control theControl
{
get{ return ctrl; }
set{ ctrl = value; }
}
}
In Form2 I add a button "button1", and set the property "theControl" to
"button1" in the Designer
public class Form2 : Form1
{
protected System.Windows.Forms.Button button1;
#region Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
// button1
this.button1.Visible = true;
// Form3
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1 });
this.Name = "Form3";
this.theControl = this.button1;
this.ResumeLayout(false);
}
#endregion
}
In the Designer for Form 3, the property "theControl" shows "ctrl" as the
value and places the following in InitializeComponents:
public class Form3 : WindowsApplication2.Form2
{
#region Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
// ctrl
this.ctrl.Name = "ctrl";
this.ctrl.Visible = true;
// Form3
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ctrl});
this.Name = "Form3";
this.ResumeLayout(false);
}
#endregion
}
When I try to compile the code I get the following errors:
'Form1.ctrl' is inaccessible due to its protection level
'Form1.ctrl' is inaccessible due to its protection level
'Form1.ctrl' is inaccessible due to its protection level
Why is the property value forcing the name of the private "ctrl" in Form1 on
"button1"?
What am I doing wrong here?
~Greg
property values in a base form.
I have 3 forms inheriting from each other in a chain:
Form1 -> Form2 -> Form3
Form1 looks like this:
public class Form1 : Form
{
private Control ctrl;
public Control theControl
{
get{ return ctrl; }
set{ ctrl = value; }
}
}
In Form2 I add a button "button1", and set the property "theControl" to
"button1" in the Designer
public class Form2 : Form1
{
protected System.Windows.Forms.Button button1;
#region Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
// button1
this.button1.Visible = true;
// Form3
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1 });
this.Name = "Form3";
this.theControl = this.button1;
this.ResumeLayout(false);
}
#endregion
}
In the Designer for Form 3, the property "theControl" shows "ctrl" as the
value and places the following in InitializeComponents:
public class Form3 : WindowsApplication2.Form2
{
#region Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
// ctrl
this.ctrl.Name = "ctrl";
this.ctrl.Visible = true;
// Form3
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ctrl});
this.Name = "Form3";
this.ResumeLayout(false);
}
#endregion
}
When I try to compile the code I get the following errors:
'Form1.ctrl' is inaccessible due to its protection level
'Form1.ctrl' is inaccessible due to its protection level
'Form1.ctrl' is inaccessible due to its protection level
Why is the property value forcing the name of the private "ctrl" in Form1 on
"button1"?
What am I doing wrong here?
~Greg