c# html 动态添加控件 属性获得,c# propertyGrid属性控件跟Htmlelement元素绑定

加入一个propertyGrid

PropertyGrid propertyGrid1 = new PropertyGrid();

propertyGrid1.CommandsVisibleIfAvailable = true;

propertyGrid1.Location = new Point(10, 20);

propertyGrid1.Size = new System.Drawing.Size(400, 300);

propertyGrid1.TabIndex = 1;

propertyGrid1.Text = "Property Grid";

this.Controls.Add(propertyGrid1);

下面是事件触发

我们对元素做例子

private void editocx_onDocumentmousedown()

{

mshtml.IHTMLElement ele=editocx.getCurElement();

if(ele==null)return;

switch(ele.tagName.ToLower())

{

case "label":

AdapterProperty(new

LabelElement(ele));

break;

//省略其他

default:

break;

}

}

AdapterProperty把对象赋值给propertyGrid的selectobject属性

private void AdapterProperty(object eleclass)

{

propertyGrid1.SelectedObject=eleclass;

}

下面是htmlelement属性适配类,以label举例,并且对label的id和name这两个属性绑定

//Add by Alice.2005-7-8

public class PropertyAdapter

{

public PropertyAdapter()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public static string getEleAttr(IHTMLElement e,string

name)

{

if(e.getAttribute(name,0)==null)return "";

return

e.getAttribute(name,0).ToString();

}

public static void setEleAttr(IHTMLElement e,string

name,string _value)

{

if(e.getAttribute(name,0)!=null){

if(_value.Equals("")||_value==null)

{

e.removeAttribute(name,0);

return;

}

e.setAttribute(name,_value,0);

return;

}

if(_value.Equals("")||_value==null)return;

e.setAttribute(name,_value,0);

}

}

public class LabelElement

{

private IHTMLElement e;

[DescriptionAttribute("The rate in milliseconds that

the text will repeat."),

CategoryAttribute("Global Settings")]

public string id

{

get

{

return e.id;

}

set

{

e.id=value;

}

}

[CategoryAttribute("Global Settings")]

public string name

{

get

{

return PropertyAdapter.getEleAttr(e,"name");

}

set

{

PropertyAdapter.setEleAttr(e,"name",value);

}

}

public LabelElement(IHTMLElement ele)

{

e=ele;

}

}

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至hey@evget.com

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值