PC Review


Reply
Thread Tools Rate Thread

Bug with multiple visual inheritence?

 
 
Gregory Persson
Guest
Posts: n/a
 
      13th Aug 2003
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


 
Reply With Quote
 
 
 
 
Erik Frey
Guest
Posts: n/a
 
      13th Aug 2003
If you want to access Form1.ctrl from a child inheritance, you need to
declare Control ctrl as protected, not private.

See Line 4: private Control ctrl;

Cheers,

Erik

"Gregory Persson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
pouya
Guest
Posts: n/a
 
      14th Aug 2003

>-----Original Message-----
>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
>
>
>.
>

 
Reply With Quote
 
pouya
Guest
Posts: n/a
 
      14th Aug 2003

>-----Original Message-----
>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
>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Visual Inheritence Sux Bob Powell [MVP] Microsoft Dot NET Framework Forms 2 25th Oct 2005 10:58 AM
Re: Visual Inheritence Sux Rob Oldfield Microsoft Dot NET Framework Forms 0 23rd Oct 2005 12:47 PM
Re: Visual Inheritence Sux J.P. HAMILTON Microsoft Dot NET Framework Forms 0 22nd Oct 2005 09:02 PM
Re: Visual Inheritence Sux Lloyd Dupont Microsoft Dot NET Framework Forms 1 22nd Oct 2005 02:22 PM
Re: Visual Inheritence Sux Yosh Microsoft Dot NET Framework Forms 0 21st Oct 2005 03:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:11 AM.