Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I have 2 controls I developed - lets call them CContanor and CItem (They aren't called that, but this makes it simpler).

 

CContanor contains many instances of CItem, and I've made a designer to assist in adding these CItems to CContanoir at designtime.

 

The problem is that when I add CItems to CContanor using the designer, it generates code which isn't suitable for my needs.

 

It creates a new instance (In the "private void InitializeComponent()" method) of each CItem, sets several properties such as name and size, and then adds the CItems to CContaner useing -

CContaner.Controls.Add(CItem);

 

which is not good - because I need these controls to be added using a custom method -

CContaner.AddMyItem(CItem);

 

So it dosn't work properly.

 

My two question are:

1)How do I change the code generation so that it uses :

CContaner.AddMyItem(CItem);

instead of-

CContaner.Controls.Add(CItem);

 

2)How do I control the properties set in the InitializeComponent() of each CItem?

Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
Posted

To assure that a property is serialized use this attribute on the property:

<System.ComponentModel.DesignerSerializationVisibility(ComponentModel.DesignerSerializationVisibility.Content)>

 

The Controls.Add problem I advise you to use the ControlAdded event on your container control instead of creating a new way of adding controls... ;)

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...