您的位置:首页 > 编程语言 > C#

C# 实现点击按钮进行页面的放大和缩小

2018-01-15 15:55 435 查看
using System.Windows.Forms;
private System.Windows.Forms.WebBrowser webBrowser1;
float times = 1.0F;
private void button1_Click(object sender, EventArgs e)
{
var Document = webBrowser1.Document;
if (times > 1.0f && Document.Body.Style != null)
{
times -= 0.1F;
}
Document.Body.Style = "transform:scale(" + (times).ToString() + ");transform-origin:top;";
}

private void button2_Click(object sender, EventArgs e)
{
var Document = webBrowser1.Document;
if (times <= 2.0f && Document.Body.Style != null)
{
times += 0.1F;
}
Document.Body.Style = "transform:scale(" + (times).ToString() + ");transform-origin:top;";
}

button2_Click:实现的是点击后页面放大;

button1_Click:实现的是点击后页面缩小;

开始使用的是zoom属性,但是zoom默认是页面左上角缩放,所以我选择了用transform属性进行缩放,transform默认是页面正中间缩放,这样会导致放大后上方内容看不到,所以我用到了另一个属性transform-origin为top,这样页面缩放则会在正上方进行。

判断中第一项是判断是否在想要的范围之内,而第二个是为了判断打开的页面中是否有style属性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐