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;
            }

        }


     

  • 相关阅读:
    mysql之创建数据库,创建数据表
    mysql之group by,order by
    一个人选出2门以上不及格的课程sql语句
    GIt入门
    数据库索引工作原理
    题目:50个人围城一圈数到3和3的倍数时出圈,问剩下的人是谁?原来的位置是多少?
    约瑟夫环:递归算法
    K-means算法的java实现,聚类分析681个三国武将
    java用一个for循环输出99乘法表
    写一个基于UDP协议的聊天小程序
  • 原文地址:https://www.cnblogs.com/alice/p/188661.html
Copyright © 2011-2022 走看看