473,387 Members | 1,388 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,387 software developers and data experts.

Orphaned custom controls

Wall, up, driven I have been.

I runtime "Controls.Add" eighteen of my custom controls (two varieties).

A seemingly random (but consistent) eleven of them instantly lose their
parentange.

I do virually anything, and the remaining magnificent seven of them drop
off the face of the form.

I don't think I'm doing anything particularly wierd. I've tried them
deriven from System.Windows.Forms.Control and ditto,UserControl (which I
don't want, 'cos I'm using Region to make irregular shaped controls).

My controls work fine at design time, and ones added then persist later
on. It's just the runtime added ones that fade into oblivion. They're
still present as objects - all they seem to have lost is their parentage.

I'm using #Develop, XP, if that makes the slightest difference.

--
Lau
http://www.bergbland.info
Get a domain from http://oneandone.co.uk/xml/init?k_id=5165217 and I'll
get the commission!

Nov 15 '05 #1
2 1094
Let's see some code. Make sure you're instiating a new object, then add it
to the parent controls collection. Adding the same control to a set of
different parent controls won't "copy" the object.

I'm sure you're aware of this, but I just wanted to point it out!

--
venlig hilsen / with regards
anders borum
--
Nov 15 '05 #2
Anders Borum wrote:
Let's see some code. Make sure you're instiating a new object, then add it
to the parent controls collection. Adding the same control to a set of
different parent controls won't "copy" the object.

I'm sure you're aware of this, but I just wanted to point it out!


Thanks for the comments, I was doing all that part fine. I had trouble
trying to come up with any *short* bit of code that exhibited the
behaviour. To cut to the answer (which is purely newbie):

I had (erroneously) latched onto "using (expression)" as a means of
typecasting - not a good idea!

using (Control C = (Control)thing.Tag) { C.Visible = true; etc... }

That makes the control visible, but then instantly disposes of it.

Trivially, I know that I should have said:

{ Control C = (Control)thing.Tag; C.Visible = true; etc... }

(it's shorter, even! :-P) duhhh )

I feel sure there ought to be some kind of error reported - rather than
the horrible side effect it was cauasing.

Is there really any use for my stupid sort of construct - given that the
compiler can see that I haven't brought a new object into existence in
the "using ()", so I'm hardly likely to want to throw anything away
(maybe it should be called the "un-using (expression)" statement! From
the SDK docs: "You *create* an instance in a using statement ..." - but
I didn't, so it's an error.

--
Lau
http://www.bergbland.info
Get a domain from http://oneandone.co.uk/xml/init?k_id=5165217 and I'll
get the commission!

Nov 15 '05 #3

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

Similar topics

7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: Suzanne | last post by:
Hi all, I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
2
by: J R M | last post by:
I've developed a custom control (it's basically a drop-down list and then a couple of textboxes to include meta-data for the selection) that I'm embedding into another custom control (the idea is...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
by: rizwanahmed24 | last post by:
Hello i have created a custom control. i have placed two template controls on it. One is check box and second is picture box. The custom control also contain two picture boxes as property. These...
2
by: Ron | last post by:
I would like some more information on custom controls, what they can do and things like that, what you would use them for etc... Can anyone here share some examples of what you have used a custom...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.