Link to home
Start Free TrialLog in
Avatar of wwwbetyar
wwwbetyar

asked on

c# CollectionBase, I lost the design time collection after build....

Hi

I want to write a component is c# with collection.
It works fine, but if I create a nem collection item in desig time,I lost this value(s) when I go to the code view or build it.

I need a fast solution....

Here is the source code :
/*
 * Created by SharpDevelop.
 * User: xxxx
 * Date: 2004.11.19.
 * Time: 22:32
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Runtime.Serialization;
//using System.Collections;

namespace xBase
{
      /// <summary>
      /// Description of UserControl1.      
      /// </summary>
            
      public class Desktop : System.Windows.Forms.UserControl
      {
            private System.ComponentModel.IContainer components;
            private System.Windows.Forms.ImageList IconImageList;
            private System.Drawing.Bitmap BkGroundBitmap = null;      
            private Desktop.MyIconsCollection fIconList = new MyIconsCollection();
            
            public Desktop()
            {
                  //
                  // The InitializeComponent() call is required for Windows Forms designer support.
                  //
                  InitializeComponent();
                  
                  //
                  // TODO: Add constructor code after the InitializeComponent() call.
                  //
            }
            
            protected override void OnResize(EventArgs e)
            {
                  Invalidate();
            }
                        
            protected override void OnPaint( PaintEventArgs pe )
            {
                  Graphics g = pe.Graphics;
                  Rectangle rect = this.ClientRectangle;
                  if (BkGroundBitmap != null)
                  {
                        g.DrawImage(BkGroundBitmap, rect);
                  } else
                  {
                        g.Clear(this.BackColor);
                  }
                  
                  if (fIconList != null)
                  {
                     if (fIconList.Count > 0)
                     {
                                 for (int a=0;a<=fIconList.Count-1;a++)
                                 {
                                       try
                                       {
                                             if ((IconImageList.Images.Count-1 >= fIconList[a].Index) && (IconImageList.Images.Count>0))
                                             {
                                                   Image IconBitmap = IconImageList.Images[fIconList[a].Index];
                                                   Bitmap bmIcon = (Bitmap)IconBitmap;
                                                   bmIcon.MakeTransparent(bmIcon.GetPixel(1,1));
                                                   g.DrawImage(bmIcon,fIconList[a].XPosition,fIconList[a].YPosition,IconBitmap.Width,IconBitmap.Height);
                                             }
                                       }
                                       catch
                                       {}
                                 }
                     }
                }
            }
            
            public ImageList IconImages
            {
                  set      {IconImageList = value; Invalidate();}
                  get {return IconImageList;}
      
            }
            public Bitmap BackGroundBitmap
            {
                  set {BkGroundBitmap = value; Invalidate();}
                  get {return BkGroundBitmap;}
            }
            
            [
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            EditorAttribute("System.ComponentModel.Design.CollectionEditor", "System.Drawing.Design.UITypeEditor")
            ]
            public Desktop.MyIconsCollection Iconlist
            {
                  get
                  {
                        if (this.fIconList == null)
                        {
                              this.fIconList = new Desktop.MyIconsCollection();
                        }
                        return this.fIconList;
                  }
            }
            

            ///
            /// Collection
            ///
            
            public sealed class Icons : Component
            {
                  private string IconCaption;
                  private int IconIndex;
                  private int IconXPosition;
                  private int IconYPosition;
                  
                  public Icons()
                  {
                        
                  }
                  
                  //[Browsable(false)]
                  public string Caption
                  {
                        set { IconCaption = value;}
                        get { return IconCaption;}
                  }
                  public int XPosition
                  {
                        set { IconXPosition = value;}
                        get { return IconXPosition;}
                  }
                  public int YPosition
                  {
                        set { IconYPosition = value;}
                        get { return IconYPosition;}
                  }
                  public int Index
                  {
                        set { IconIndex = value;}
                        get { return IconIndex;}
                  }
                  
            }
          
          [Serializable]
          public sealed class MyIconsCollection : System.Collections.CollectionBase
            {
                  public int Add(Icons item)
                  {
                        return List.Add(item);
                  }
                  public void Insert(int index, Icons item)
                  {
                        List.Insert(index,item);
                  }
                  public void Remove(Icons item)
                  {
                        List.Remove(item);
                  }
                  public bool Contains(Icons item)
                  {
                        return List.Contains(item);
                  }
                  public int IndexOf(Icons item)
                  {
                        return List.IndexOf(item);
                  }
                  public void CopyTo(Icons[] array,int index)
                  {
                        List.CopyTo(array,index);
                  }
                  public Icons this[int index]
                  {
                        get {return(Icons)List[index];}
                        set {List[index] = value;}
                  }
            }
            
            #region Windows Forms Designer generated code
            /// <summary>
            /// This method is required for Windows Forms designer support.
            /// Do not change the method contents inside the source code editor. The Forms designer might
            /// not be able to load this method if it was changed manually.
            /// </summary>
            private void InitializeComponent() {
                  this.components = new System.ComponentModel.Container();
                  this.IconImageList = new System.Windows.Forms.ImageList(this.components);
                  //
                  // IconImageList
                  //
                  this.IconImageList.ImageSize = new System.Drawing.Size(16, 16);
                  this.IconImageList.TransparentColor = System.Drawing.Color.Transparent;
                  //
                  // Desktop
                  //
                  this.Name = "Desktop";
                  this.Size = new System.Drawing.Size(292, 266);
            }
            #endregion
      }
}
ASKER CERTIFIED SOLUTION
Avatar of tomvergote
tomvergote
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wwwbetyar
wwwbetyar

ASKER

yes I use the lastest version so I"m not sure that is the bug.
I think you should try posting this to the sharpdevelop forums or mailinglists as it seems clear that it's something with their designer.
You create a collection in design view and it isn't reflected in code.
I tryed it in visual studio !
It works fine , so I will write  to the sharpdevelop forums....