一、HtmlEvent 事件:Html元素事件,HtmlEditor將容器內HTML中的全部事件統一冒泡到此事件中進行處理。在此事件的處理函數中可根據不一樣的事件類型進行不一樣的業務處理。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; } } }
二、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(); }
三、BeforePaste 事件:內容粘貼前事件,此事件將在用戶進行粘貼操做前觸發,在此事件中可對粘貼的內容進行過濾整理,如處理從Word過來的數據,Excel過來的數據,清除吊沒必要要的內容等。this
/// <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); } } }
三、BeforeNavigate 事件,頁面導航前事件,此事件將在頁面進行導航跳轉前觸發,可在此事件中進行阻止跳轉。spa