开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 12782|回复: 0

HTMLUI研究

[复制链接]

0

精华

84

贡献

130

赞扬

帖子
210
软币
2538
在线时间
438 小时
注册时间
2014-2-15
发表于 2018-3-2 17:21:09 | 显示全部楼层 |阅读模式
HTMLUI可以加载HTML页面,并且相比WebKit等占用资源特别少


[C#] 纯文本查看 复制代码
(1)HTMLUI源码中绘制部分

复制代码
/// <summary>
/// Starts the drawing of the document from the start element.
/// </summary>
/// <param name="e">Paint event data.</param>
private void ProcessDraw(PaintEventArgs e)
{
    if (e == null)
        throw new ArgumentNullException("e");

    if (m_startDrawElement == null)
    {
        this.RenderRoot.DrawElement(e);
    }
    else
    {
        m_startDrawElement.DrawElement(e);

        // Reset start element.
        m_startDrawElement = null;
    }
}
复制代码
如果m_startDrawElement为null,在根html tag下绘制,否则在指定元素下绘制。
(2)FlowLayoutPanel中使用HTMLUI时,要先用一个UserControl或者其它控件作为HTMLUI的父控件,不然滚动时会出现花屏现象。

(3)动态改变HTMLUI元素内容代码

复制代码
private void htmluiControl1_PreRenderDocument(object sender, Syncfusion.Windows.Forms.HTMLUI.PreRenderDocumentArgs e)
        {
            Hashtable htmlelements = new Hashtable();
            htmlelements = e.Document.ElementsByUserID;
            Label lable=new Label();
            lable.Text = "1";
            lable.Width = 24;
            lable.Height = 24;
            lable.BackColor = Color.Red;
            BaseElement aaa = htmlelements["aaa"] as BaseElement;
                new CustomControlBase(aaa, lable);

        }

        private void ChangeLableValue(HTMLUIControl htmluiControl,string str)
        {

            var v = htmluiControl.Document.GetElementsByUserIdHash()["aaa"];
            Label v1= htmluiControl.Document.GetControlByElement((IHTMLElement) v) as Label;
            v1.Text = str;
        }
复制代码
 

(4)FlowLayoutPanel使用PreRenderDocument时,有时创建会报线程间操作无效: 从不是创建控件“”的线程访问它,经检查原因在PreRenderDocument,修改PreRenderDocument如下。

复制代码
private void htmluiControl1_PreRenderDocument(object sender, Syncfusion.Windows.Forms.HTMLUI.PreRenderDocumentArgs e)
        {
            Hashtable htmlelements = new Hashtable();
            htmlelements = e.Document.ElementsByUserID;

            Action<Hashtable> action = (data) =>
            {
                Label lable = new Label();
                lable.Text = "1";
                lable.Width = 24;
                lable.Height = 24;
                lable.BackColor = Color.Red;
                BaseElement aaa = htmlelements["aaa"] as BaseElement;
                new CustomControlBase(aaa, lable);
            };
            Invoke(action, htmlelements);

        }
复制代码



回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-19 10:58

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表