添加窗体居中显示功能并优化资源释放

This commit is contained in:
LittleBoy 2025-04-14 22:32:54 +08:00
parent 7e26695000
commit 7cfab47216
4 changed files with 33 additions and 0 deletions

Binary file not shown.

View File

@ -112,6 +112,12 @@ namespace AIProofread.Controls
this.FormBorderStyle = FormBorderStyle.None; this.FormBorderStyle = FormBorderStyle.None;
} }
public void SetHeight(int height)
{
this.Height = height;
CenterToScreen();
}
protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null) protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null)
{ {
//Bridge.InitWebEnvAsync(name, webView); //Bridge.InitWebEnvAsync(name, webView);

View File

@ -14,6 +14,19 @@ namespace AIProofread.Controls
public FormLogin() public FormLogin()
{ {
InitializeComponent(); InitializeComponent();
this.FormClosed += (s, e) =>
{
// 关闭时释放资源
try
{
if (web != null)
{
web.Dispose();
web = null;
}
}
catch { };
};
//Bridge.InitWebEnvAsync("login", web); //Bridge.InitWebEnvAsync("login", web);
//Bridge.AddEventHandler(BridgeEvent.LoginSuccess, OnLoginSuccess); //Bridge.AddEventHandler(BridgeEvent.LoginSuccess, OnLoginSuccess);
} }
@ -21,6 +34,19 @@ namespace AIProofread.Controls
{ {
this.action = action; this.action = action;
InitializeComponent(); InitializeComponent();
this.FormClosed += (s, e) =>
{
// 关闭时释放资源
try
{
if (web != null)
{
web.Dispose();
web = null;
}
}
catch { };
};
} }
private void OnLoginSuccess(object sender, EventArgs e) private void OnLoginSuccess(object sender, EventArgs e)

View File

@ -39,6 +39,7 @@ namespace AIProofread.Controls
{ {
this.Width = (int)(width * dpiScaleFactor); this.Width = (int)(width * dpiScaleFactor);
this.Height = (int)(height * dpiScaleFactor); this.Height = (int)(height * dpiScaleFactor);
CenterToScreen();
} }
private void FormWebView_Load(object sender, EventArgs e) private void FormWebView_Load(object sender, EventArgs e)