C#自定义组件在属性面板显示问题 我自定义了一个c#控件,其中一个属性的取值是固定的几个值,我希望开发人员将这个控件放入窗体,修改这个属性时用ComboBox风格进行选择,而不是直接输入(这样有可能会输错),就象listBox的BorderStyle 属性那样.请指教最好能给个小例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex==0 ) linkLabel1.BorderStyle = BorderStyle.FixedSingle; else if (comboBox1.SelectedIndex==1 ) linkLabel1.BorderStyle=BorderStyle.Fixed3D; else linkLabel1.BorderStyle=BorderStyle.None; //linkLabel1.Update; } 其中一个属性的取值是固定的几个值=======定义一个枚举类型,来包含这几个值,修改这个属性时用ComboBox风格进行选择,而不是直接输入(这样有可能会输错),就象listBox的BorderStyle 属性那样.=====某个属性类型是枚举类型之后, VS Designer 自动支持,下来选择看看 BorderStyle 就是一个枚举类型 定义一个枚举类型,再根据属性获得的值重绘控件例如在你的自定义了控件的代码中加入下面代码,其他开发人员将这个控件放入窗体后,就要以在属性栏找到ComboBoxStyle属性,然后就可以选“平面”、“立体”两项了public enum eComboBoxStyle{ 平面, 立体}private eComboBoxStyle comboBoxStyle;/// <summary>/// ComboBox样式/// </summary>public eComboBoxStyle ComboBoxStyle{ get { return comboBoxStyle; } set { comboBoxStyle = value; switch (comboBoxStyle) { case eComboBoxStyle.平面 : //写代码重绘控件 break; case eComboBoxStyle.立体 : //写代码重绘控件 break; } }} 如何将属性加在控制面板中,我找到一个例子.[CategoryAttribute("自定义的复杂类型设置(包括自定义类型转换器)"), TypeConverterAttribute(typeof(PropertyGridApp.FileNameConverter)), ReadOnlyAttribute(false)] 我在网上找到一个例子可以编绎的出错, 提示 PropertyGridApp 没有找到类型.namespace StyleOcx{ /// <summary> /// FileNameConverter 的摘要说明。 /// </summary> public class FileNameConverter:System.ComponentModel.StringConverter { public FileNameConverter() { // // TODO: 在此处添加构造函数逻辑 // } public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { return true; } public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { return new StandardValuesCollection(new string[]{"File1.bat","File2.exe","File3.dll"}); } public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { return true; } }} 1.修改这个属性时用ComboBox风格进行选择,而不是直接输入用枚舉,樓上的說得很清楚了,不明白,可以查一下資料2.如何將屬性增加到控製面板中/// <summary>/// 當前操作DataTable對象/// </summary>[DescriptionAttribute("當前操作DataTable對象"),CategoryAttribute("擴展屬性"),DefaultValueAttribute(null)]public DataTable myDataTable{ get{return _myDataTable;}} c# 复制搞好了,想做个像列表一样的控件,显示已经复制好的文件,用哪个控件? 还是字符格式化的问题,第二次提问》》》》 关于文本框字体问题 线程销毁 以及线程里的对象关闭 C#技术文档 C#里面的窗口,如何截获自定义的这些消息? 串口类。自动接收到的数据。 怎么传到窗口上啊 +——| 小问题紧急求救!!!! ◆★请问怎么实现自定义字段,就是由客户自定义数据表中字段★◆两个帖子给100分!!! 如何使得DataGrid的一列显示为下拉框的形式? 求助:不加访问修饰符的类 如何实现单击按钮打开新的窗口.
{
if (comboBox1.SelectedIndex==0 ) linkLabel1.BorderStyle = BorderStyle.FixedSingle;
else if (comboBox1.SelectedIndex==1 )
linkLabel1.BorderStyle=BorderStyle.Fixed3D;
else
linkLabel1.BorderStyle=BorderStyle.None;
//linkLabel1.Update;
}
修改这个属性时用ComboBox风格进行选择,而不是直接输入(这样有可能会输错),就象listBox的BorderStyle 属性那样.=====某个属性类型是枚举类型之后, VS Designer 自动支持,下来选择看看 BorderStyle 就是一个枚举类型
例如在你的自定义了控件的代码中加入下面代码,其他开发人员将这个控件放入窗体后,就要以在属性栏找到ComboBoxStyle属性,然后就可以选“平面”、“立体”两项了public enum eComboBoxStyle
{
平面,
立体
}private eComboBoxStyle comboBoxStyle;/// <summary>
/// ComboBox样式
/// </summary>
public eComboBoxStyle ComboBoxStyle
{
get { return comboBoxStyle; }
set
{
comboBoxStyle = value;
switch (comboBoxStyle)
{
case eComboBoxStyle.平面 :
//写代码重绘控件
break;
case eComboBoxStyle.立体 :
//写代码重绘控件
break;
}
}
}
我在网上找到一个例子可以编绎的出错, 提示 PropertyGridApp 没有找到类型.
namespace StyleOcx
{
/// <summary>
/// FileNameConverter 的摘要说明。
/// </summary>
public class FileNameConverter:System.ComponentModel.StringConverter
{
public FileNameConverter()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { return true; }
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { return new StandardValuesCollection(new string[]{"File1.bat","File2.exe","File3.dll"}); }
public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { return true; }
}
}
用枚舉,樓上的說得很清楚了,不明白,可以查一下資料
2.如何將屬性增加到控製面板中
/// <summary>
/// 當前操作DataTable對象
/// </summary>
[DescriptionAttribute("當前操作DataTable對象"),CategoryAttribute("擴展屬性"),DefaultValueAttribute(null)]
public DataTable myDataTable
{
get{return _myDataTable;}
}