天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

WinForm控件開發總結(七)-----為復雜屬性的子屬性提供編輯功能

      前面的幾篇文章中,我們給控件添加一個復雜的類型Scope,并且給它的類型提供的一個類型轉換器,現在我們可以在屬性瀏覽器中編輯它的值,并且它的值也被串行化的源代碼里了。但是你有沒有發現,在屬性瀏覽器里編輯這個屬性的值還是不太方便。因為屬性只是“10200這種形式的,所以,你必須按照這種格式來修改,一旦格式錯誤就會引發異常,比如輸入一個“10200。我們期望這個屬性的每一子屬性都能夠被獨立的編輯就好了,這并非不能實現,而且實現還很簡單。
      為了在屬性瀏覽器里能夠獨立的編輯子屬性,我們還要重寫兩個方法:GetPropertiesSupported()和GetProperties();下面是ScopeConverter的完整代碼:
   public class ScopeConverter : TypeConverter
    
{
        
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        
{
            
if (sourceType == typeof(String)) return true;

            
return base.CanConvertFrom(context, sourceType);
        }


        
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        
{
            
if (destinationType == typeof(String)) return true;

            
if (destinationType == typeof(InstanceDescriptor)) return true;

            
return base.CanConvertTo(context, destinationType);
        }


        
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.
CultureInfo culture, 
object value, Type destinationType)
        
{
            String result 
= "";
            
if (destinationType == typeof(String))
            
{
                Scope scope 
= (Scope)value;
                result 
= scope.Min.ToString()+"," + scope.Max.ToString();
                
return result;

            }


            
if (destinationType == typeof(InstanceDescriptor))
            
{
                ConstructorInfo ci 
= typeof(Scope).GetConstructor(new Type[] {typeof(Int32),
typeof
(Int32) }
);
                Scope scope 
= (Scope)value;
                
return new InstanceDescriptor(ci, new object[] { scope.Min,scope.Max });
            }

            
return base.ConvertTo(context, culture, value, destinationType);
        }


        
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.
CultureInfo culture, 
object value)
        
{
            
if (value is string)
            
{
                String[] v 
= ((String)value).Split(',');
                
if (v.GetLength(0!= 2)
                
{
                    
throw new ArgumentException("Invalid parameter format");
                }


                Scope csf 
= new Scope();
                csf.Min 
= Convert.ToInt32(v[0]);
                csf.Max 
= Convert.ToInt32(v[1]);
                
return csf;
            }

            
return base.ConvertFrom(context, culture, value);
        }


        
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        
{
            
return true;
        }


        
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context,
object
 value, Attribute[] attributes)
        
{
            
return TypeDescriptor.GetProperties(typeof(Scope), attributes);
        }

}

NET技術WinForm控件開發總結(七)-----為復雜屬性的子屬性提供編輯功能,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: CHINA学生白嫩 | 美女被撕开胸罩狂揉大乳 | jizz非洲 | 欧美久久无码AV麻豆 | china chinese中国人玩 | 手机看片国产免费久久网 | 疯狂做受XXXX高潮欧美日本 | 国产 高清 无码 中文 | 极品少妇小泬50PTHEPON | 2020精品国产视 | 国产精品女主播主要上线 | 亚洲乱码中文字幕久久孕妇黑人 | 精品国产国偷自产在线观看 | 午夜国产精品视频 | 久久水蜜桃亚洲AV无码精品偷窥 | 入禽太深免费视频10 | 亚洲AV无码乱码A片无码蜜桃 | 亚洲AV美女成人网站P站 | 久久精品视在线观看2 | 日本免费一本天堂在线 | 任你躁国语自产二区在线播放 | 儿子好妈妈的HD3中字抢劫 | 手机在线观看无码日韩视频 | 亚洲精品高清AV在线播放 | 国产成人aaa在线视频免费观看 | 精品国产乱码久久久久久夜深人妻 | 啦啦啦 中文 日本 韩国 免费 | 日本少妇无码精品12P | 中文日产无乱码AV在线观 | 狂野欧美性猛XXXX乱大交 | 善良的小峓子2在钱中文版女主角 | 高hnp肉文| 久久精品视频15人人爱在线直播 | 亚洲免费无码中文在线亚洲在 | 97视频在线免费播放 | 日韩毛片在线视频 | 午夜影院费试看黄 | 成人女人A级毛片免费软件 成人免费在线视频 | 里番※琉璃全彩acg奈亚子 | 久9视频这里只有精品123 | 在线欧美 精品 第1页 |