就是将自定义控件拖到窗体上时,查看属性时,自定义的属性上显示默认值。。

解决方案 »

  1.   

    在你的自定义控件的Value或者Text属性设置默认值;
    我理解的对吗?
      

  2.   

    参考
    http://www.cnblogs.com/tedzhao/archive/2008/05/10/1190772.html
    版本通过AssembliInfo设置
      

  3.   

    直接给get里面的字段设置初始值,或者使用属性的<defaultvalue(10)>
      

  4.   

    写错了  [DefaultValue(...)]
      

  5.   

    [default(....)] 不行啊 ,没有在右边的属性框中显示默认值啊。。
      

  6.   

    // [DefaultValue("aabb")]
            public string Mywujj
            {
                get
                {
                    wujj = "dd";
                    return wujj;
                }            set
                {
                    wujj = value;
                }
            }这样不行啊  
      

  7.   

    EventAttribute有:
    BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultEventAttribute
    PropertyAttribute有:
    BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultPropertyAttribute、DefaultValueAttribute、EditorAttribute 、DesignerSerializationVisibilityAttribute、TypeConverterAttribute、BindableAttribute、LocalizableAttribute       上述的Attribute简明阐述如下:
                 BrowsableAttribute:在Property窗口中是否可见。
                 CategoryAttribute:Property或者Event所属的哪个组。
                 DescriptionAttribute:Property或者Event的简单描述。
                 DefaultEventAttribute:默认Event、。
                 DefaultPropertyAttribute:默认Property,选中组件,其Property窗口中默认选中在这个Property上。
                 DefaultValueAttribute:Property的默认值,选中组件,其Event窗口中默认选中在这个Event上。
      

  8.   

    [DefaultValue("默认值")],在属性前加类似这种写法的语句就可以了
      

  9.   


    using System.ComponentModel;
      

  10.   

    [BrowsableAttribute(true)]
            public string Mywujj
            {
                get
                {
                    wujj = "dd";
                    return wujj;
                }            set
                {
                    wujj = value;
                }
            }还是不行啊
      

  11.   


    我怀疑你的属性的权限不是public,所以在VS的IDE环境下不显示
      

  12.   

    崩溃了  改成public一样,还是不行
      

  13.   

    源代码:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;namespace NumBox
    {
        public partial class WNumBox : TextBox
        {
            public string wujj;        private string laststr = "";
            private string firststr = "";        public WNumBox()
            {
                //InitializeComponent();            this.ReadOnly = true;
                this.BackColor = Color.White;            this.KeyDown += new KeyEventHandler(MyKeyDown);
            }      
            [BrowsableAttribute(true)]
            public string Mywujj
            {
                get
                {
                    wujj = "dd";
                    return wujj;
                }            set
                {
                    wujj = value;
                }
            }                public void MyKeyDown(object send, KeyEventArgs e)
            {
                string strn = "";
                int num = e.KeyValue;            if (num >= 48 && num <= 57)
                {
                    firststr = this.Text.Substring(0, this.SelectionStart);
                    laststr = this.Text.Substring(this.SelectionStart, this.Text.Length - firststr.Length);                this.Text = firststr + ((char)num).ToString() + laststr;                this.SelectionStart = firststr.Length + 1;
                }
                else
                {
                    if (num == 96) strn = "0";
                    if (num == 97) strn = "1";
                    if (num == 98) strn = "2";
                    if (num == 99) strn = "3";
                    if (num == 100) strn = "4";
                    if (num == 101) strn = "5";
                    if (num == 102) strn = "6";
                    if (num == 103) strn = "7";
                    if (num == 104) strn = "8";
                    if (num == 105) strn = "9";                if (strn != "")
                    {
                        firststr = this.Text.Substring(0, this.SelectionStart);
                        laststr = this.Text.Substring(this.SelectionStart, this.Text.Length - firststr.Length);                    this.Text = firststr + strn + laststr;                    this.SelectionStart = firststr.Length + 1;
                    }
                }            //按backspace删除
                if (num == 8)
                {
                    if (this.Text != "" && this.SelectionStart > 0)
                    {
                        firststr = this.Text.Substring(0, this.SelectionStart);
                        laststr = this.Text.Substring(this.SelectionStart, this.Text.Length - firststr.Length);                    this.Text = firststr.Substring(0, firststr.Length - 1) + laststr;                    this.SelectionStart = firststr.Length - 1;
                    }
                }
                //按delete删除
                if (num == 46)
                {
                    if (this.SelectionStart < this.Text.Length)
                    {
                        firststr = this.Text.Substring(0, this.SelectionStart);
                        laststr = this.Text.Substring(this.SelectionStart, this.Text.Length - firststr.Length);                    this.Text = firststr + laststr.Substring(1, laststr.Length - 1);                    this.SelectionStart = firststr.Length;
                    }
                }
            }
        }
    }
      

  14.   

    只要帮我看一下   Mywujj   属性就可以了,谢谢各位了! 
      

  15.   


     DefaultProperty("Text")
      

  16.   

    我已经写了
    wujj = "dd"; 
      

  17.   

    DefaultValueAttribute will NOT automatically set your property. 
    It is used for display (in bold or not) and for resetting values.So, you need to set the value yourself:
    class UserControl1 : UserControl
    {
       private int myLength = 8;                //<---
       [DefaultValue(8)]
       public int MyLength
       {
          get {return this.myLength; }
          set {this.myLength = value; }
       }
    }
      

  18.   

    疯掉了 ,还是不行
    我是将这个代码(控件)生成一个dll文件,然后在另一个窗体中添加这个dll文件,是不是跟这个有问题啊??
      

  19.   


    Stay calm :)
    Remember to re-compile, and also drag a new control to see the change.
      

  20.   

          public EastTestBox()
            {
                InitializeComponent();
            }        public enum ControlStyle
            {
                TextBox,
                ComboBox,
                Select
            }
            private ControlStyle style = ControlStyle.ComboBox;
            [Description("控件样式"), DefaultValue(ControlStyle.ComboBox), Browsable(true)]
            public ControlStyle Style
            {
                get
                {
                    return style;
                }
                set
                {
                    style = value;
                }
            }
      

  21.   

    高手帮我解决下下面问题
    就是属性做成弹出窗口进行多种操作后的返回值
    就想font属性一样
    谢谢
      

  22.   

    21楼正解,设置DefaultValue是不行的
      

  23.   

    这个帖子真有意思,学习下!(08年的帖子到现在还没结贴~~~~~~~~~嘿嘿~~~~)这段时间也在尝试着自定义控件,有个问题,我的自定义中有个Combox,自定义了获取或设置它的数据源。但是在使用这个控件的项目中的属性面板添加数据源。没有成功。
    弹出来的窗口和ComBox的Items小窗口不一样。还不能设置值。
    是不是跟我定义的这个自定义属性的类型有关系啊?我用的是ArrayList。