标签:des style blog io color os ar for sp
HtmlDocument2 HTML文档对象模型:
主要方法有:
场景1:用于在当前选中位置插入html代码。
var selRange = doc2.GetSelection().createRange() as IHTMLTxtRange; if (selRange != null){ selRange.pasteHTML("<input type=‘text‘/>"); }
场景2:获取当前选中的控件
var controlRange=doc2.GetSelection().createRange() as IHTMLControlRange; if(controlRange!=null){ var length = controlRange.GetLength(); for (int i = 0; i < length;i++ ) { var control = controlRange.Item(i); } }
5.GetStyleSheets() 获取样式表,进行样式设置
IHTMLStyleSheetsCollection sheets = CurrentDocument.GetStyleSheets();//获取样式表 IHTMLStyleSheet sheet = null; if (sheets.length == 0)//样式表长度为0,则新增 { sheet = CurrentDocument.CreateStyleSheet("", 0); } else //大于0,则获取第一个样式表 { object i = 0; sheet = sheets.item(ref i) as IHTMLStyleSheet; } CommonArgs args = new CommonArgs(); args.Tag = sheet.GetCssText();//获取当前样式表的样式 HtmlViewCssStyleEditForm styleform = new HtmlViewCssStyleEditForm(args); if (styleform.ShowDialog() == DialogResult.OK) { try { sheet.SetCssText(args.Tag.ToString());//设置样式 _currentFormDesignFormModel.ViewStyleRules.Clear(); IHTMLStyleSheetRulesCollection rules = sheet.GetRules(); for (int i = 0; i < rules.GetLength(); i++) { var rule = rules.Item(i).GetSelectorText(); if (rule.Length > 1 && rule.StartsWith(".")) { var gciStyleRule = new GciStyleRule(); 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) { } }
标签:des style blog io color os ar for sp
原文地址:http://www.cnblogs.com/liaotongquan/p/4062295.html