就是将自定义控件拖到窗体上时,查看属性时,自定义的属性上显示默认值。。
解决方案 »
- 请教C#重写C++ DLL中的方法。。
- 请帮忙看看修改区域语言后,实时生效的方法.为何无效?
- 求一个树形的算法 拜谢了!
- 如何在datagridview间互导数据?
- webBrowser问题
- 回到水源求助。.NET托管程序的弊病?谁能帮忙解决?
- 如何查找一段字符串的位置
- 在win xp下开发c#数据库应用安装什么版本的sql server好啊?
- 如何把一个表示时日的string转换成datetime?
- 求救:装有dX9 SDK(c#)的朋友请帮忙!
- C#中用SaveFileDialog类保存文件,如何另外增加字符编码(ANSI、UTF-8等)选项
- BulletedList控件怎么改变第一个Item和第二个Item之间的行间距?
我理解的对吗?
http://www.cnblogs.com/tedzhao/archive/2008/05/10/1190772.html
版本通过AssembliInfo设置
public string Mywujj
{
get
{
wujj = "dd";
return wujj;
} set
{
wujj = value;
}
}这样不行啊
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上。
using System.ComponentModel;
public string Mywujj
{
get
{
wujj = "dd";
return wujj;
} set
{
wujj = value;
}
}还是不行啊
我怀疑你的属性的权限不是public,所以在VS的IDE环境下不显示
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;
}
}
}
}
}
DefaultProperty("Text")
wujj = "dd";
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; }
}
}
我是将这个代码(控件)生成一个dll文件,然后在另一个窗体中添加这个dll文件,是不是跟这个有问题啊??
Stay calm :)
Remember to re-compile, and also drag a new control to see the change.
{
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;
}
}
就是属性做成弹出窗口进行多种操作后的返回值
就想font属性一样
谢谢
弹出来的窗口和ComBox的Items小窗口不一样。还不能设置值。
是不是跟我定义的这个自定义属性的类型有关系啊?我用的是ArrayList。