zoukankan      html  css  js  c++  java
  • c# propertyGrid属性控件跟Htmlelement元素绑定(原创精华)

    加入一个propertyGrid

    PropertyGrid propertyGrid1 = new PropertyGrid();
    propertyGrid1.CommandsVisibleIfAvailable 
    = true;
                propertyGrid1.Location 
    = new Point(1020);
                propertyGrid1.Size 
    = new System.Drawing.Size(400300);
                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;
            }

        }


     

  • 相关阅读:
    AtCoder Regular Contest 066 F Contest with Drinks Hard
    AtCoder Grand Contest 002 D
    AtCoder Regular Contest 076 F
    AtCoder Grand Contest 004 C
    AtCoder Regular Contest 067 F
    转载:Unity3D游戏对象消失enabled、Destroy与active的区别
    Unity3d-AngryBots实例解读
    本类对象的引用作为参数,可以直接访问其私有成员
    构建完全二叉树、控制台打印二叉树
    转载:C++类内存分布
  • 原文地址:https://www.cnblogs.com/alice/p/188661.html
Copyright © 2011-2022 走看看