[英]How to increase or decrease web browser control font size using button?
[英]How to increase or decrease web browser font size using button in windows phone?
嗨,我正在使用下面给出的代码。我想使用A +和A-按钮在Web浏览器上增加或减少文本字体大小。我正在从xml feed.html获取html文件,因此在此解决方案中有任何帮助来解决。
<phone:WebBrowser x:Name="webBrowser" Height="592" IsScriptEnabled="True" />
<Button BorderThickness="0" Margin="0,0,18,0" Height="88" HorizontalAlignment="Right" Width="96" x:Uid="#aPlus" Click="A-_Click" >
private void A-_Click(object sender, RoutedEventArgs e)
{
if (i > 2)
{
webBrowser.FontSize -= 2;
i++;
j = i;
}
}
private void A+_Click(object sender, RoutedEventArgs e)
{
if (i < 3)
{
webBrowser.FontSize += 2;
i++;
j = i;
}
}
<Fullcontent>
<html>
<body>
<p>When worn right, there’s nothing quite like gold and Shilpa seems to have pulled off the look in style on Nach Baliye 5. Other stars spotted were Ajay Devgn and Akshay Kumar with Kajal Agarwal promoting their film Special 26. Though Kajal looked pretty in an Anarkali, she could not quite compete with Shilpa.</p>
</body>
</html>
</Fullcontent>
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
webBrowser.NavigateToString(App.CurrentArticle.FullContent);
}
}
我正在使用此代码,但没有任何更改字体大小的方法。所以请帮助我任何人如何解决此解决方案。
您必须使用WebBrowser.InvokeScript:
// Initial text size
int textSize = 100; // Percentage
private void A+_Click(object sender, EventArgs e)
{
textSize *= 2; // Can modify to not increase so much each time
string szfn = "{styleText = \"body { -ms-text-size-adjust:" + textSize + "% }\";styleTextNode = document.createTextNode(styleText);styleNode = document.createElement(\"style\");styleNode.appendChild(styleTextNode);document.getElementsByTagName(\"head\")[0].appendChild(styleNode);};";
webBrowser.InvokeScript("eval", szfn);
}
private void A-_Click(object sender, EventArgs e)
{
textSize /= 2; // Can modify to not decrease so much each time
string szfn = "{styleText = \"body { -ms-text-size-adjust:" + textSize + "% }\";styleTextNode = document.createTextNode(styleText);styleNode = document.createElement(\"style\");styleNode.appendChild(styleTextNode);document.getElementsByTagName(\"head\")[0].appendChild(styleNode);};";
webBrowser.InvokeScript("eval", szfn);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.