473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Controls and Parent

The Control class has the Parent property that is readonly.
When the control is added to a controls collection of another control the
Parent property refers to that control.
"Who" set the Parent property? How to implement this "mechanism"?

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}
}

public class MyControlCollection : ArraList
{
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
//I think here schould be set the parent property, but how???
return this.Add(control);
}
}

Any help will be appreciated , thanks
Nov 16 '05 #1
5 2351
I think this must be web Control? (Windows Forms control, Parent is not
read-only.)
If there is no set, then you can't change it. What do you really need to
accomplish? You could create your own writable property on MyControl to tell
which if any MyControlCollection it was in. Maybe that will serve your
purpose?

-Rachel

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:O1**************@TK2MSFTNGP15.phx.gbl...
The Control class has the Parent property that is readonly.
When the control is added to a controls collection of another control the
Parent property refers to that control.
"Who" set the Parent property? How to implement this "mechanism"?

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}
}

public class MyControlCollection : ArraList
{
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
//I think here schould be set the parent property, but how???
return this.Add(control);
}
}

Any help will be appreciated , thanks

Nov 16 '05 #2
I don't want a writable property, I want to prevent such things like:

controls[0].Parent=new MyControl();

or

controls[0].Parent=null;

"Rachel Suddeth" <ra****@bldhound.com> schrieb im Newsbeitrag
news:em**************@TK2MSFTNGP10.phx.gbl...
I think this must be web Control? (Windows Forms control, Parent is not
read-only.)
If there is no set, then you can't change it. What do you really need to
accomplish? You could create your own writable property on MyControl to
tell which if any MyControlCollection it was in. Maybe that will serve
your purpose?

-Rachel

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:O1**************@TK2MSFTNGP15.phx.gbl...
The Control class has the Parent property that is readonly.
When the control is added to a controls collection of another control the
Parent property refers to that control.
"Who" set the Parent property? How to implement this "mechanism"?

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}
}

public class MyControlCollection : ArraList
{
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
//I think here schould be set the parent property, but how???
return this.Add(control);
}
}

Any help will be appreciated , thanks


Nov 16 '05 #3
One possibility:

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}

public MyControl()
{
controls = new MyControlCollection(this);
}

}

public class MyControlCollection : ArraList
{
protected MyControl owner;

public MyControlCollection(MyControl p)
{
owner= p;
}
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
control.Parent = owner;
return this.Add(control);
}
}

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:O1**************@TK2MSFTNGP15.phx.gbl...
The Control class has the Parent property that is readonly.
When the control is added to a controls collection of another control the
Parent property refers to that control.
"Who" set the Parent property? How to implement this "mechanism"?
Any help will be appreciated , thanks

Nov 16 '05 #4
You can't say control.Parent = owner if Parent is readonly (which seems to
be the case for web controls.)

Zuercher, I am assuming you've found out from experience that Adding a
control to a conrol collection automatically resets the conrol.Parent
property? I think then, that you could do something like:

Control SaveParent = MyControl.Parent;
SaveParent.Remove(MyControl); // not sure if this is necessary, but
shouldn't hurt
MyControlCollection.Add(MyControl);
SaveParent.Add(MyControl).

Then the most recent Add would be done to the "real" parent, so you would be
restoring the Parent property. Make sense? (I haven't tried it, it's just an
idea.)

-Rachel
"James Curran" <Ja*********@mvps.org> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
One possibility:

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}

public MyControl()
{
controls = new MyControlCollection(this);
}

}

public class MyControlCollection : ArraList
{
protected MyControl owner;

public MyControlCollection(MyControl p)
{
owner= p;
}
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
control.Parent = owner;
return this.Add(control);
}
}

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:O1**************@TK2MSFTNGP15.phx.gbl...
The Control class has the Parent property that is readonly.
When the control is added to a controls collection of another control the
Parent property refers to that control.
"Who" set the Parent property? How to implement this "mechanism"?

Any help will be appreciated , thanks


Nov 16 '05 #5
Rachel is right; "Parent" is read-only. So, I played around with Lutz
Roeder's Reflector, and figured out how it's done. This trick is that
AddedControl can change the private member of the parameter, because both
are MyControls.

public class MyControlCollection : ArraList
{
protected MyControl owner;

public MyControlCollection(MyControl p)
{
owner= p;
}
protected new int Add(object value){return base.Add(value);}
public virtual Add(MyControl control)
{
owner.AddedControl(control);
return this.Add(control);
}
}

public abstract class MyControl
{
private MyControl parent;
public MyControl Parent{get{return this.parent;}}

private MyControlCollection controls;
public MyControlCollection Controls{get{return controls;}}

public MyControl()
{
controls = new MyControlCollection(this);
}

public void AddedControl(MyControl child)
{
child.parent = this;
}

}
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brindley | last post by:
Hi there, In my Mdi application, I have placed a set of controls on the parent form to call child forms. The problem is that the controls hide the child forms. I have used SendToBack when Im...
0
by: DotNetJunkies User | last post by:
Hi All I am developing a site using ASP.Net I want to develop a site that generates forms ( textbox,check boxes etc) automatically ie is from database itself depending on the no of rows in the...
0
by: mawi | last post by:
Hello, Description: I create panels with some controls on a page using a new panel button. One of the controls on each panel is the "close panel" button that is supposed to close the panel it...
1
by: Homam | last post by:
So I have a composite paging control that shoulld be positioned on the page like this: PagNav ResultSetDisplay PagNav I know that I can't resuse the PagNav more than once in the form, so I...
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
5
by: tshad | last post by:
I have a PageInit.ascx that I want to put in all my pages and have it execute only once during the "not IsPostback" section. I also need it to execute first before anything else. I have it set...
6
by: Ronald S. Cook | last post by:
We have a Windows app that has one main form (a shell, sort of). We then load user controls into a panel on the form depending on what the user has selected. Our current code to unload the...
4
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
4
by: Andrew | last post by:
I want to create a set of Activity Diagram controls for process control. I need to create a base Diagram control that acts as a container for the Activity controls ( StartPoint, EndPoint,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.