Files
VNCServerList/Form1.cs
2025-07-07 17:05:06 +09:00

60 lines
1.6 KiB
C#

using System;
using System.Windows.Forms;
using Microsoft.Web.WebView2.WinForms;
using Microsoft.Owin.Hosting;
using VNCServerList.Web;
namespace VNCServerList
{
public partial class Form1 : Form
{
private WebView2 webView;
private IDisposable webApp;
public Form1()
{
InitializeComponent();
StartWebServer();
InitializeWebView();
}
private async void InitializeWebView()
{
webView = new WebView2();
webView.Dock = DockStyle.Fill;
this.Controls.Add(webView);
try
{
await webView.EnsureCoreWebView2Async(null);
webView.CoreWebView2.Navigate("http://localhost:8080");
}
catch (Exception ex)
{
MessageBox.Show($"WebView2 초기화 중 오류가 발생했습니다: {ex.Message}", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void StartWebServer()
{
try
{
var options = new StartOptions("http://localhost:8080");
webApp = WebApp.Start<Startup>(options);
}
catch (Exception ex)
{
MessageBox.Show($"웹 서버 시작 중 오류가 발생했습니다: {ex.Message}", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
webApp?.Dispose();
base.OnFormClosing(e);
}
}
}