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

        }


     

  • 相关阅读:
    JAVA共通関数文字列の長さを求める
    JAVA共通関数文字コード変換
    JAVA共通関数文字列に空白を追加する
    JAVA共通関数 半角英数字チェック
    JAVA共通関数項目が半角09か判断する
    JAVA共通関数 指定日の曜日を算出する
    linux添加静态路由(rhel5.4)
    ubuntu编译opencapwap报错解决
    Wireshark网络抓包(二)——过滤器
    net.ipv4.tcp_tw_recycle、net.ipv4.tcp_tw_reuse回收tcp连接总结
  • 原文地址:https://www.cnblogs.com/alice/p/188661.html
Copyright © 2020-2023  润新知