翻譯|其它|編輯:郝浩|2006-06-26 13:54:00.000|閱讀 2480 次
概述:
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
加入一個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);
下面是事件觸發
我們對<label>元素做例子
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;
}
}
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn