Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winUserControl in VS2010 - properties are not visible in designer

I have a problem with (I suppose) my Visual Studio 2010 Express environment: when I design my own UserControl, in Properties grid I can't see public properties of that control. They are however visible in the project, that reference this control.
As it's Express Edition, I create new empty project, then add new UserControl to it.
Then, for a test, I put following code:

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;

namespace Project1
{
    public partial class UserControl1 : UserControl
    {
        private int myNumber;

        [Browsable(true)]
        public int MyNumber
        {
            get
            {
                return myNumber;
            }
            set
            {
                myNumber = value;
            }
        }


        public UserControl1()
        {
            InitializeComponent();
        }
    }
}  

In VS 2008, as I remember, that should be enogh to show MyNumber property in Properties grid, even without [Browsable(true)] attribute. In VS 2010 however, when I double click UserControl1.cs in Solution Explorer and look in Properties, I don't see MyNumber.
When I reference and use this control in another project, there is an access to it's properties.

I've tried to competly reinstall VS 2010 environment, including SP1, but with no success. Do you have any idea what can be wrong?

By the way: none of these attributes are working, either:

[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Bindable(true)]

Best regards,
Marcin

like image 821
mj82 Avatar asked Aug 16 '11 14:08

mj82


People also ask

How to see properties in VS code?

You can find Properties Window on the View menu. You can also open it by pressing F4 or by typing Properties in the search box. The Properties window displays different types of editing fields, depending on the needs of a particular property.


1 Answers

I believe this the normal behavior of VS2010 and assume it's by design. It behaves the same for me in 2010 Ultimate. When you place UserControl1 on a form, you'll see its custom properties.

My guess is this is because when you're designing the control, there is no instance of your control yet (it may not have even been compiled). What you're looking at is an instance of UserControl. When you compile your control and then add it to a form, the designer creates an instance of your control, so its properties can be seen and manipulated.

like image 194
Igby Largeman Avatar answered Sep 18 '22 16:09

Igby Largeman