HtmlDocument2 HTML Document Object model:
The main methods are:
- GetBody () Gets the current document body object
- GetReadyState () Gets the current document state information, such as whether it is loading, has completed, and the enumeration value is: Uninitialized,loading,loaded,interactive,complete
- ExecCommand () Executes the command, such as ExecCommand ("Multipleselection", false, true); Indicates that the current document allows multiple-selection controls
- GetSelection () Gets the current selection area, which is used for two scenarios:
Scenario 1: Use to insert HTML code at the currently selected location.
var as IHTMLTxtRange; if NULL { selrange.pastehtml ("<input type= ' text '/>"); }
Scenario 2: Get the currently selected control
var as Ihtmlcontrolrange; if (controlrange!=null) { var length = controlrange.getlength (); for (int0; i < length;i++ ) { var control = Controlrange.item (i); } }
5.GetStyleSheets () Get style sheet, style settings
IHTMLStyleSheetsCollection sheets = currentdocument.getstylesheets ();//Get style sheetIHTMLStyleSheet sheet =NULL; if(Sheets.length = =0)//style sheet length is 0, the new{Sheet= Currentdocument.createstylesheet ("",0); } Else //greater than 0, gets the first style sheet { Objecti =0; Sheet= Sheets.item (refI asIHTMLStyleSheet; } Commonargs args=NewCommonargs (); Args. Tag= Sheet. Getcsstext ();//gets the style of the current style sheetHtmlviewcssstyleeditform Styleform =Newhtmlviewcssstyleeditform (args); if(Styleform. ShowDialog () = =DialogResult.OK) {Try{sheet. Setcsstext (args. Tag.tostring ());//Set Style_currentformdesignformmodel.viewstylerules.clear (); IHTMLStyleSheetRulesCollection Rules=sheet. GetRules (); for(inti =0; I < rules. GetLength (); i++) { varRule =rules. Item (i). Getselectortext (); if(rule. Length >1&& rule. StartsWith (".")) { varGcistylerule =NewGcistylerule (); Gcistylerule.name= Rule. Substring (1); Gcistylerule.ruletext=rules. Item (i). GetStyle (). Getcsstext (); _currentformdesignformmodel.viewstylerules.add (Gcistylerule); }} _currentformdesignformmodel.currentview.viewcssstyle=args. Tag.tostring (); } Catch(Exception ex) {}}
HtmlDocument2 of HTMLEditor Class object description