c# property属性和改变编辑多行文本
一个常见的属性的使用。其中name 属性没有定义私有字段,而age定义了已有字段。
public sealed class employee {
// this property is an automatically implemented property
public string name { get; set; }
private int32 m_age;
public int32 age {
get { return(m_age); }
set {
if (value < 0) // the 'value' keyword always identifies the new value.
throw new argumentoutofrangeexception("value", value.tostring(),
"the value must be greater than or equal to 0");
m_age = value;
}
}
}
改变 propertygrid 控件的编辑风格(2)——编辑多行文本
效果:
适用场合:
1、 编辑多行文本;
2、 编辑长文本。
步骤一:定义从uitypeeditor 派生的类,示例如下:
using system;
using system.windows.forms;
using system.drawing.design;
using system.windows.forms.design;
namespace blog.111com.net.zhangyuk
{
///
/// propertygridmutitext 的摘要说明。
///
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.111com.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();
}
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔