public MainForm() { InitializeComponent(); try { Instance = this; Hwnd = Handle; mp.Init(); mp.Shutdown += Shutdown; mp.VideoSizeChanged += VideoSizeChanged; mp.FileLoaded += FileLoaded; mp.Idle += Idle; mp.Seek += () => UpdateProgressBar(); mp.observe_property_bool("pause", PropChangePause); mp.observe_property_bool("fullscreen", PropChangeFullscreen); mp.observe_property_bool("ontop", PropChangeOnTop); mp.observe_property_bool("border", PropChangeBorder); mp.observe_property_string("sid", PropChangeSid); mp.observe_property_string("aid", PropChangeAid); mp.observe_property_string("vid", PropChangeVid); mp.observe_property_int("edition", PropChangeEdition); if (mp.GPUAPI != "vulkan") { mp.ProcessCommandLine(false); } AppDomain.CurrentDomain.UnhandledException += (sender, e) => Msg.ShowError(e.ExceptionObject.ToString()); Application.ThreadException += (sender, e) => Msg.ShowException(e.Exception); Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; Text = "mpv.net " + Application.ProductVersion; TaskbarButtonCreatedMessage = Native.RegisterWindowMessage("TaskbarButtonCreated"); object recent = RegHelp.GetObject(App.RegPath, "Recent"); if (recent is string[] r) { RecentFiles = new List <string>(r); } else { RecentFiles = new List <string>(); } ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; if (mp.Screen == -1) { mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen); } int targetIndex = mp.Screen; Screen[] screens = Screen.AllScreens; if (targetIndex < 0) { targetIndex = 0; } if (targetIndex > screens.Length - 1) { targetIndex = screens.Length - 1; } Screen screen = screens[Array.IndexOf(screens, screens[targetIndex])]; Rectangle target = screen.Bounds; Left = target.X + (target.Width - Width) / 2; Top = target.Y + (target.Height - Height) / 2; int posX = RegHelp.GetInt(App.RegPath, "PosX"); int posY = RegHelp.GetInt(App.RegPath, "PosY"); if (posX != 0 && posY != 0 && App.RememberPosition) { Left = posX - Width / 2; Top = posY - Height / 2; } if (App.Maximized) { WindowState = FormWindowState.Maximized; } } catch (Exception ex) { Msg.ShowException(ex); } }
public MainForm() { InitializeComponent(); try { Instance = this; Hwnd = Handle; mp.Init(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += Application_ThreadException; Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; WPF.WPF.Init(); System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; Text += " " + Application.ProductVersion; object recent = RegHelp.GetObject(App.RegPath, "Recent"); if (recent is string[] r) { RecentFiles = new List <string>(r); } else { RecentFiles = new List <string>(); } var wpfColor = WPF.WPF.ThemeColor; Color color = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B); ToolStripRendererEx.InitColors(color, App.IsDarkMode); ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; App.ProcessCommandLineEarly(); if (mp.Screen == -1) { mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen); } int targetIndex = mp.Screen; Screen[] screens = Screen.AllScreens; if (targetIndex < 0) { targetIndex = 0; } if (targetIndex > screens.Length - 1) { targetIndex = screens.Length - 1; } Screen screen = screens[Array.IndexOf(screens, screens[targetIndex])]; Rectangle target = screen.Bounds; Left = target.X + (target.Width - Width) / 2; Top = target.Y + (target.Height - Height) / 2; int posX = RegHelp.GetInt(App.RegPath, "PosX"); int posY = RegHelp.GetInt(App.RegPath, "PosY"); if (posX != 0 && posY != 0 && App.RememberPosition) { Left = posX - Width / 2; Top = posY - Height / 2; } mp.Shutdown += Shutdown; mp.VideoSizeChanged += VideoSizeChanged; mp.FileLoaded += FileLoaded; mp.Idle += Idle; mp.VideoSizeAutoResetEvent.WaitOne(1500); if (Height < FontHeight * 4) { SetFormPosAndSize(); } mp.observe_property_bool("fullscreen", PropChangeFullscreen); mp.observe_property_bool("ontop", PropChangeOnTop); mp.observe_property_bool("border", PropChangeBorder); mp.observe_property_string("sid", PropChangeSid); mp.observe_property_string("aid", PropChangeAid); mp.observe_property_string("vid", PropChangeVid); mp.observe_property_int("edition", PropChangeEdition); } catch (Exception ex) { Msg.ShowException(ex); } }