首页 > 代码库 > HTMLEditor类常用事件说明

HTMLEditor类常用事件说明

1、HtmlEvent 事件:Html元素事件,HtmlEditor将容器内HTML中的所有事件统一冒泡到此事件中进行处理。在此事件的处理函数中可根据不同的事件类型进行不同的业务处理。

eg:

  /// <summary>        /// 编辑器Html事件处理函数        /// </summary>        /// <param name="s"></param>        /// <param name="e"></param>        private void HtmlDesignEditorHtmlEvent(object s, HtmlEventArgs e)        {            if (e.Event == null)            {                return;            }            var sEventType = e.Event.EventType.ToLower();            var isNeedToDealEvent = IsNeedToDealEvent(e);            if (isNeedToDealEvent)            {                switch (sEventType)                {                    case "controlselect":                        //_udfSelectedControl = e.Event.SrcElement;                        break;                    case "beforeeditfocus":                        if (e.Event.SrcElement.tagName.ToLower() != "body")                        {                            e.Event.ReturnValue = false;                            e.Event.CancelBubble = true;                        }                        break;                    case "click":                        {                            e.Event.ReturnValue = false;                            e.Event.CancelBubble = true;                        }                        break;                    case "drop":                        //DoDropEvent                        DoDropEvent(e);                        break;                    case "dragover":                        //DoDragOverEvent                        break;                    case "dragend":                        //DoDragEndEvent                        DoDragEndEvent(e);                        break;                    case "dragenter":                        //DoDragEnter                        DoDragEnterEvent(e);                        break;                    case "mouseover":                        //DoMouseOverEvent                        DoMouseOverEvent(e);                        break;                    case "mousemove":                        //DoMouseMove                        DoMouseMoveEvent(e);                        break;                    case "mousedown":                        //DoMouseDown                        MultiMouseDownEvent(e);                        DoMouseDownEvent(e);                        break;                    case "mouseout":                        //DoMouseOut                        DoMouseOutEvent(e);                        break;                    case "mouseup":                        //DoMouseUp                        DoMouseUpEvent(e);                        break;                    case "mousewheel":                        //DoMouseWheel                        DoMouseWheelEvent(e);                        break;                    case "resizeend":                        DoResizeEndEvent(e);                        break;                    case "resizestart":                        DoResizeStartEvent(e);                        break;                    case "keydown":                        break;                    case "dblclick":                        DoDblClickEvent(e);                        break;                    default:                        DoFinish(e);                        break;                }            }        }

2、ContentChanged  事件:容器内容改变事件,此事件将会在容器内容更改后触发

 /// <summary>        /// HTML编辑器内容改变事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void HtmlDesignEditorContentChanged(object sender, EventArgs e)        {            if (_isDoDragEnd || _isChangeHtml)            {                _behaviorManage.Clear();                _behaviorManage.AddTableBehavior(htmlDesignEditor.DocumentHTML);                _behaviorManage.AddToolTipBehavior(htmlDesignEditor.DocumentHTML);                _behaviorManage.AddDateTimeBehavior(htmlDesignEditor.DocumentHTML);                _isChangeHtml = false;                _isDoDragEnd = false;            }            FindViewControls();        }

3、BeforePaste 事件:内容粘贴前事件,此事件将在用户进行粘贴操作前触发,在此事件中可对粘贴的内容进行过滤整理,如处理从Word过来的数据,Excel过来的数据,清除吊不必要的内容等。

   /// <summary>        /// HTML编辑器进行粘贴操作前处理函数,此事件可对需要粘贴的数据进行预处理        /// </summary>        /// <param name="s"></param>        /// <param name="e"></param>        private void HtmlDesignEditorBeforePaste(object s, BeforePasteArgs e)        {            if (Clipboard.ContainsText(TextDataFormat.Html))            {                e.Cancel = true;                MemoryStream memoryStream = Clipboard.GetData("Html Format") as MemoryStream;                if (memoryStream == null)                {                    return;                }                memoryStream.Position = 0;                var vBytes = new byte[memoryStream.Length];                memoryStream.Read(vBytes, 0, (int) memoryStream.Length);                var sText = Encoding.UTF8.GetString(vBytes);                IHTMLDocument2 doc = this.htmlDesignEditor.HtmlDocument2;                IHTMLTxtRange sel = doc.GetSelection().createRange() as IHTMLTxtRange;                var controlSel = doc.GetSelection().createRange() as IHTMLControlRange;                var length = controlSel.GetLength();                for (int i = 0; i < length;i++ )                {                    var control = controlSel.Item(i);                }                    if (sel == null)                    {                        return;                    }                var html = _coolPf.CreateHtml(sText);                sel.pasteHTML(html);                //idManager.AdjustmentElementID(Me.contentEditor.HtmlDocument2)                //  behaviorManage.AddTableBehavior(contentEditor.DocumentHTML);                IHTMLElementCollection elList = this.htmlDesignEditor.DocumentHTML.GetElementsByTagName("TABLE");                foreach (IHTMLElement el in elList)                {                    el.SetAttribute("height", el.offsetHeight, 0);                }                elList = this.htmlDesignEditor.DocumentHTML.GetElementsByTagName("TR");                foreach (IHTMLElement el in elList)                {                    el.SetAttribute("height", el.offsetHeight, 0);                }            }        }

3、BeforeNavigate 事件,页面导航前事件,此事件将在页面进行导航跳转前触发,可在此事件中进行阻止跳转。

 

HTMLEditor类常用事件说明