如何在windows phone中使用按钮增加或减少网页浏览器字体大小

How to increase or decrease web browser font size using button in windows phone?

本文关键字:网页 网页浏览 浏览器 字体 增加 windows phone 按钮      更新时间:2023-09-26

我正在使用下面给出的代码。我想增加或减少使用A+和A-按钮的网页浏览器上的文本字体大小。我从XML提要得到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&rsquo;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);
}

>