国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

改變 PropertyGrid 控件的編輯風格(4)——加入選擇列表

2024-07-21 02:24:07
字體:
來源:轉載
供稿:網友

改變 propertygrid 控件的編輯風格(4)——加入選擇列表

 

張昱[email protected] 效果:

適用場合:

限制選擇輸入

 

步驟一:定義從uitypeeditor 繼承的抽象類:comboboxitemtypeconvert。示例如下:

using system;

using system.collections;

using system.componentmodel;

 

namespace blog.csdn.net.zhangyuk

{

     /// imstypeconvert 的摘要說明。

     /// </summary>

     public abstract class comboboxitemtypeconvert : typeconverter

     {

         public hashtable _hash = null;

 

         public comboboxitemtypeconvert()

         {

              _hash = new hashtable();

              getconverthash();

         }

 

         public abstract void getconverthash();

 

         public override bool getstandardvaluessupported( itypedescriptorcontext context )

         {

              return true;

         }

 

         public override standardvaluescollection getstandardvalues(

itypedescriptorcontext context)

         {

              int [] ids = new int [ _hash.values.count ];

 

              int i=0;

              foreach (dictionaryentry myde in _hash)

              {

                   ids[i++] = (int)(myde.key);

              }

 

              return new standardvaluescollection( ids );

         }

         public override bool canconvertfrom( itypedescriptorcontext context, type sourcetype)

         {

              if (sourcetype == typeof(string))

              {

                   return true;

              }

              return base.canconvertfrom(context, sourcetype);

         }

 

         public override object convertfrom(

itypedescriptorcontext context, 

system.globalization.cultureinfo culture,

object v )

         {

              if (v is string)

              {

                   foreach (dictionaryentry myde in _hash)

                   {

                       if( myde.value.equals((v.tostring())) )

                            return myde.key;

                   }

              }

              return base.convertfrom(context, culture, v);

         }

 

         public override object convertto( 

itypedescriptorcontext context, 

system.globalization.cultureinfo culture, object v ,

type destinationtype)

         { 

              if (destinationtype == typeof(string))

              {

                   foreach (dictionaryentry myde in _hash)

                   {

                       if( myde.key.equals(v) )

                            return myde.value.tostring();

                   }

                   return "";

              }

              return base.convertto(context, culture, v, destinationtype);

         }

 

         public override bool getstandardvaluesexclusive(

              itypedescriptorcontext context)

         {

              return false;

         }       

     }

}

 

步驟二:定義 comboboxitemtypeconvert 的派生類,派生類中實現父類的抽象方法:

public abstract void getconverthash();

示例如下:

 

using system;

using system.collections;

using system.componentmodel;

 

namespace blog.csdn.net.zhangyuk

{

     public class propertygridboolitem : comboboxitemtypeconvert

     {

         public override void getconverthash()

         {

              _hash.add(0,"是");

              _hash.add(1,"否");

         }

     }

 

     public class propertygridcomboboxitem : comboboxitemtypeconvert

     {

         public override void getconverthash()

         {

              _hash.add(0,"炒肝");

              _hash.add(1,"豆汁");

              _hash.add(2,"灌腸");

         }

     }

}

 

步驟三:編輯屬性類,指定編輯屬性。示例如下:

namespace blog.csdn.net.zhangyuk

{

         public class someproperties

     {

         private string _finished_time   = "";

                   ……

         // 布爾

         bool _bool = true;

         [

              description("布爾"),

              category("屬性"),

              typeconverter(typeof( propertygridboolitem ))

         ]

         public int 布爾

         {

              get { return _bool == true ? 0 : 1; }

              set { _bool = (value == 0 ? true : false); }

         }

 

         // 選擇列表

         int _comboboxitems = 0;

         [

              description("選擇列表"),

              category("屬性"),

              typeconverter(typeof( propertygridcomboboxitem ))

         ]

         public int 選擇列表

         {

              get { return _comboboxitems;  }

              set { _comboboxitems = value; }

         }

         ……

         }

}

 

步驟四:設置propertygrid的屬性對象。示例如下:

         private void form1_load(object sender, system.eventargs e)

         {

            this.propertygrid1.selectedobject = new someproperties();          }

收集最實用的網頁特效代碼!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼图壁县| 中牟县| 昆山市| 苏州市| 周宁县| 张家港市| 芜湖市| 隆化县| 广水市| 青田县| 甘泉县| 兰州市| 乐亭县| 鄂托克前旗| 平定县| 莱州市| 滨州市| 广丰县| 冀州市| 深泽县| 武威市| 武夷山市| 黔南| 长宁区| 焉耆| 漳浦县| 三门县| 余干县| 荆门市| 屏山县| 元谋县| 澄城县| 错那县| 吉木萨尔县| 莱阳市| 梧州市| 北辰区| 吉安市| 荣昌县| 达拉特旗| 肥西县|