52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace AIProofread.Controls
|
||
{
|
||
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||
[ComVisible(true)]
|
||
public partial class FormWebView : BaseWinForm
|
||
{
|
||
public string WebUrl { get; set; }
|
||
private double dpiScaleFactor;
|
||
public FormWebView(string url,int width,int height)
|
||
{
|
||
InitializeComponent();
|
||
this.WebUrl = url;
|
||
|
||
this.dpiScaleFactor = this.label1.Width / 42.0; // 设置的宽度为42,实际渲染宽度 / 42 即为缩放比例
|
||
|
||
Screen screen = Screen.FromControl(this);
|
||
|
||
this.SetSize(width, height);
|
||
this.StartPosition = FormStartPosition.CenterScreen;
|
||
}
|
||
|
||
public void SetTitle(string title)
|
||
{
|
||
this.Text = title;
|
||
}
|
||
|
||
public void SetSize(int width, int height)
|
||
{
|
||
this.Width = (int)(width * dpiScaleFactor);
|
||
this.Height = (int)(height * dpiScaleFactor);
|
||
CenterToScreen();
|
||
}
|
||
|
||
private void FormWebView_Load(object sender, EventArgs e)
|
||
{
|
||
// 初始化
|
||
InitWebView(WebView,this.WebUrl, "webview");
|
||
}
|
||
}
|
||
}
|