1

Microsoft WebBrowser コントロール (MSHTML) で現在選択されているテキストのフォント サイズを取得する方法はありますか?

については認識してIHTMLDocument2::queryCommandState("FontSize", ...)いますが、このメソッドは、古いフォント サイズ「xx-small」から「xx-large」に対して、1 から 7 の間の値しか返しません。「10pt」や「14px」などのフォント サイズの場合、有用な値は返されません。

フォント サイズを決定するより柔軟な方法はありますか?

編集:その間、私は自分の質問に対する解決策を見つけました (Microsoft サポートからのいくつかの役立つヒント付き):

try
{
   mshtml.IHTMLTxtRange range = _dom.selection.createRange() as mshtml.IHTMLTxtRange;
   if (range != null)
   {
       mshtml.IHTMLElement2 elem = range.parentElement() as mshtml.IHTMLElement2;
       txtFontSize.Text = elem.currentStyle.fontSize.ToString();

   }
}
catch (COMException ex)
{
}
4

2 に答える 2

1

入手方法がわかったので、ここで設定方法を説明します。

mshtml.HTMLDocument doc = [Obtain HtmlDocument];
doc.execCommand("FontSize", false, "12pt");

使用できる値を取得するには

doc.queryCommandValue("FontSize");
于 2010-10-01T16:32:29.630 に答える
0
IHTMLDocument2 htmlDocument = browser.Document.DomDocument as IHTMLDocument2;

IHTMLSelectionObject sel = (IHTMLSelectionObject)htmlDocument.selection;
IHTMLTxtRange range = (IHTMLTxtRange)sel.createRange() as IHTMLTxtRange;

if (range != null)
{
   range.select();
   var x = range.queryCommandValue("bold");
   textBoxFindData.Text = (x.ToString());
}
于 2015-05-20T12:25:14.100 に答える