改变 propertygrid 控件的编辑风格(3)——打开对话框

适用场合:

1、   打开文件、打印设置等通用对话框

2、   打开特定的对话框

 

 

步骤一:定义从uitypeeditor 派生的类,以 openfiledialog 对话框为例,示例代码如下:

using system;

using system.windows.forms;

using system.drawing.design;

using system.windows.forms.design;

 

 

namespace blog.csdn.net.zhangyuk

{

     /// <summary>

     /// imsopenfileinpropertygrid 的摘要说明。

     /// </summary>

     public class propertygridfileitem : uitypeeditor

     {

         public override uitypeeditoreditstyle geteditstyle(

system.componentmodel.itypedescriptorcontext context)

         {

              return uitypeeditoreditstyle.modal;

         }

        

         public override object editvalue(

system.componentmodel.itypedescriptorcontext context,

system.iserviceprovider provider,

object value)

         {           

              iwindowsformseditorservice edsvc = (iwindowsformseditorservice)

provider.getservice(typeof(iwindowsformseditorservice));

              if( edsvc != null )

              {

                   // 可以打开任何特定的对话框

                   openfiledialog dialog = new openfiledialog();

                   dialog.addextension = false;

                   if( dialog.showdialog().equals(dialogresult.ok) )

                   {

                       return dialog.filename;

                   }

              }

              return value;

         }

     }

}

 

 

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

namespace blog.csdn.net.zhangyuk

{

         public class someproperties

     {

         private string _finished_time   = "";

                   ……

         // 文件

         string _filename = "";

         [

              description("文件打开对话框"),

              category("属性"),

            editorattribute(typeof(propertygridfileitem),

typeof(system.drawing.design.uitypeeditor))

         ]

         public string 文件

         {

              get { return _filename; }

              set { _filename = value;}

         }

         ……

         }

}

 

 

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

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

         {

            this.propertygrid1.selectedobject = new someproperties();

         }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值