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

        }


     

  • 相关阅读:
    牌型种数|2015年蓝桥杯B组题解析第七题-fishers
    加法变乘法|2015年蓝桥杯B组题解析第六题-fishers
    九数组分数|2015年蓝桥杯B组题解析第五题-fishers
    [Oracle]Oracle学习小结(1)
    [Oracle]Oracle数据库任何用户密码都能以sysdba角色登入
    【oracle】Enterprise Manager 无法连接到数据库实例。下面列出了组件的状态---个人解决方案
    从两个字符串中找出最大公共子字符串
    Java学习小结(1)-数组的创建与传参
    php学习日志(5)-解决Windows Live Writer错误:WindowsLive.Writer.CoreServices.HttpRequestHelper的类型初始值设定发生异常
    php学习日志(4)-The mbstring extension is missing. Please check your PHP configuration错误及解决方法
  • 原文地址:https://www.cnblogs.com/alice/p/188661.html
Copyright © 2011-2022 走看看