改变 propertygrid 控件的编辑风格(2)——编辑多行文本

适用场合:

1、   编辑多行文本;

2、   编辑长文本。

 

 

步骤一:定义从uitypeeditor 派生的类,示例如下:

using system;

using system.windows.forms;

using system.drawing.design;

using system.windows.forms.design;

 

 

namespace blog.csdn.net.zhangyuk

{

     /// <summary>

     /// propertygridmutitext 的摘要说明。

     /// </summary>

     public class propertygridrichtext : uitypeeditor

     {

         public override uitypeeditoreditstyle geteditstyle(

system.componentmodel.itypedescriptorcontext context)

         {

              return uitypeeditoreditstyle.dropdown;

         }

        

         public override object editvalue(

system.componentmodel.itypedescriptorcontext context,

system.iserviceprovider provider,

object value)

         {      

              try

              {

                   iwindowsformseditorservice edsvc = (iwindowsformseditorservice)

provider.getservice(typeof(iwindowsformseditorservice));

                   if( edsvc != null )

                   {

                       if( value is string )

                       {

                            richtextbox box = new richtextbox();

                            box.text = value as string;

                            edsvc.dropdowncontrol( box );

                            return box.text;

                       }

                   }

              }

              catch( exception ex )

              {

                   system.console.writeline( "propertygridrichtext error : " + ex.message );

                   return value;

              }

              return value;

         }

     }

}

 

 

步骤二:编辑属性类,指定编辑属性。示例如下:

namespace blog.csdn.net.zhangyuk

{

         public class someproperties

     {

         private string _finished_time   = "";

                   ……

         // 多行文本编辑框

         string _mutilinesample = "";

         [

              description("多行文本编辑框"),

              category("属性"),

            editorattribute(typeof(propertygridrichtext),

typeof(system.drawing.design.uitypeeditor))

         ]

         ]

         public string 多行文本

         {

              get { return _mutilinesample; }

              set { _mutilinesample = value;}

         }

         ……

         }

}

 

 

步骤三:设置propertygrid的属性对象。示例如下:

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

         {

            this.propertygrid1.selectedobject = new someproperties();

         } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值