Question Problems with user control and public properties

Adagio.hpt

New member
Joined
Oct 3, 2014
Messages
4
Programming Experience
5-10
I'm currently trying to create a user control, where one of the properties is a list of an MenuItem class. Here's the code I have so far:

C#:
private List<MenuItem> menuItems = new List<MenuItem>();

        [Browsable(true)]
        public List<MenuItem> MenuItems
        {
            get
            {
                return menuItems;
            }
            set
            {
                menuItems = value;
                RefreshDisplay();
            }
        }

public void RefreshDisplay()
        {
            int row = 0;

            panelMenu.Controls.Clear();

            foreach (MenuItem item in MenuItems)
            {
                PictureBox pic = new PictureBox();

                pic.Image = item.DefaultImage;
                pic.Size = MenuItemSize;
                pic.BorderStyle = System.Windows.Forms.BorderStyle.None;
                pic.Location = new Point(Spacing + (MenuItemSize.Width * row), Spacing);

                panelMenu.Controls.Add(pic);

                row++;
            }
        }

[Serializable()]
    public class MenuItem
    {
        public string Text
        {
            get;
            set;
        }

        public Image DefaultImage
        {
            get;
            set;
        }

        public MenuItem()
        {

        }

    }

What I'm trying to do is make it possible in the form designer (where this user control is being) to be able to set the items. I'm thinking a bit the same way as for example you can do using the TabPage, where you can open a TabPage collection editor, from where you can set the different properties of the tab pages

Using that code I can add MenuItems using properties, where it opens a MenuItem Collections Editor. From the look of it, it seems like exactly what I'm looking for.
Unfortunately it doesn't work. When I add an item using the MenuItem Collections Editor it does something to my solution, making it impossible to build. It comes with the error "Could not load file or assembly CommonTools.dll or one of it's dependencies. An Attemt was made to load a program with an incorrect format. Line 167, position 5 in BasicMenuForm.resx. BasicMenuForm has nothing to do with CommonTools.dll. When I open up the file and look at the lines it just says this:

C#:
(shortened the file)
OQ+6ArRDcxu3vCotMBfWuAJAZXhRfhG3IQ8XfWsD+GJDfMAG4lvp3fUcWzikMwDS8AaTf2tt/O0JRQAA
AABJRU5ErkJgggs=
</value>
  </data> // This is line 167
</root>

Nothing really useful there. It doesn't help to go in and delete the added menuitem. I have to delete the user control from the form before I can build the solution.

In my solution I have two projects: InfoCenter and CommonTools. InfoCenter is where I have the user control and all forms. CommonTools is my own library of tools I'm using in other projects also. InfoCenter has a reference to CommonTools. The form I'm using for testing is a fresh form, there is nothing else on the form or in the code.


Does anybody have any idea what could be the problem here?
 

Latest posts

Back
Top Bottom