Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3437984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:07:55+00:00 2026-05-18T08:07:55+00:00

I have a custom user control that fires an exception when trying to add

  • 0

I have a custom user control that fires an exception when trying to add it to the designer view. (More information on that bug here)

I was told that I have to tell the designer to not acknowledge that control so it does not serialize it. I found this MSDN article that seems to do what I want. I’m assuming this will fix my error, hopefully! 🙂 (If you have better ideas please let me know how to fix this bug.)

How can I add that metadata to my class to Hidden or Content? Thanks!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ComponentModel.Design.Serialization;

namespace WinformsPlayground
{
    [DesignerSerializerAttribute()] //THE QUESTION IS HERE!
    public partial class HorizontalPictureScroller : UserControl
    {
        public HorizontalPictureScroller()
        {
            InitializeComponent();
            Pictures = new ObservableCollection<SelectablePicture>();
            Pictures.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Pictures_CollectionChanged);
        }       

        #region "Properties"
        public ObservableCollection<SelectablePicture> Pictures { get; set; }
        private int PositionControlX = 0;
        #endregion

        #region "Methods"
        private void RedrawPictures()
        {
            PositionControlX = 0;

            foreach (var picture in Pictures)
            {
                picture.Location = new Point(PositionControlX + panelPicturesWrapper.AutoScrollPosition.X, 0);
                PositionControlX += 130;
                panelPicturesWrapper.Controls.Add(picture);
            }
        }

        public void AddPicture(SelectablePicture picture)
        {
            Pictures.Add(picture);
        }

        public void RemovePicture(SelectablePicture picture)
        {
            Pictures.Remove(picture);
        }

        public void MovePictureLeft(int index)
        {
            SelectablePicture tmpPicture = Pictures[index];
            Pictures[index] = Pictures[index - 1];
            Pictures[index - 1] = tmpPicture;
        }

        public void MovePictureRight(int index)
        {
            SelectablePicture tmpPicture = Pictures[index];
            Pictures[index] = Pictures[index + 1];
            Pictures[index + 1] = tmpPicture;
        }
        #endregion

        #region "Events"
        void Pictures_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            RedrawPictures();
        }
        #endregion
    }
}

EDIT: Following advice here I added this to the top of the class but I receive an error when compiling.

namespace WinformsPlayground
{
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public partial class HorizontalPictureScroller : UserControl
    {
        public HorizontalPictureScroller()
        {
            InitializeComponent();
            Pictures = new ObservableCollection<SelectablePicture>();
            Pictures.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Pictures_CollectionChanged);
        }  

Error is:

Error 1 Attribute
‘DesignerSerializationVisibility’ is
not valid on this declaration type. It
is only valid on ‘method, property,
indexer, field, event’
declarations. C:\Users\Sergio.Tapia\documents\visual
studio
2010\Projects\WinformsPlayground\WinformsPlayground\HorizontalPictureScroller.cs 15 6 WinformsPlayground

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:07:56+00:00Added an answer on May 18, 2026 at 8:07 am

    I’m not sure, but it may be choking on your public serializable list of pictures. Just for testing, I would try adding the following immediately above this one property on your class

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

    I believe if you make it hidden, it won’t make it an editable value from the properties sheet, and thus not actually try to write the object’s serialization content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom user control that contains asp:ValidationSummary . It is placed on
I have this ListView that displays a custom user control. The custom user control
I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have a custom user control with a textbox on it and I'd like
I have a custom validation function in JavaScript in a user control on a
I have a custom WinForms control (inherits from control, i.e. without user interface jsut
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of
I have a Windows form which hosts a custom User Control. This User Control
I have a List in my custom user control. I'd like the control to
I have a very specific problem. I have a user control (code below) That

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.