改變 propertygrid 控件的編輯風(fēng)格(2)——編輯多行文本
張昱[email protected] 效果:
適用場(chǎng)合:
1、 編輯多行文本;
2、 編輯長(zhǎng)文本。
步驟一:定義從uitypeeditor 派生的類(lèi),示例如下:
using system;
using system.windows.forms;
using system.drawing.design;
using system.windows.forms.design;
namespace blog.csdn.net.zhangyuk
{
/// <summary>
/// propertygridmutitext 的摘要說(shuō)明。
/// </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;
}
}
}
步驟二:編輯屬性類(lèi),指定編輯屬性。示例如下:
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;}
}
……
}
}
步驟三:設(shè)置propertygrid的屬性對(duì)象。示例如下:
private void form1_load(object sender, system.eventargs e)
{
this.propertygrid1.selectedobject = new someproperties();
}
新聞熱點(diǎn)
疑難解答
圖片精選