/// <summary> /// 在UI執行緒執行 /// </summary> /// <param name="ac"></param> public static void fun_UI執行緒(Action ac) { C_Adapter.Invoke(new SendOrPostCallback(obj => { // 呼叫UI執行緒 ac(); }), null); }
public MainWindow() { InitializeComponent(); C_Adapter.Initialize(); c_視窗改變大小 = new C_視窗拖曳改變大小(this); this.SourceInitialized += new System.EventHandler(c_視窗改變大小.MainWindow_SourceInitialized);//右下角拖曳 //初始化web wbo = new WebBrowserOverlay(border_web); web_資料夾 = wbo.WebBrowser; //初始化頁籖物件 Action <String> ac_點擊 = new Action <String>((String x) => { String s_path = func_取得儲存根目錄() + "\\" + x; if (bool_單層儲存路徑) { s_path = func_取得儲存根目錄(); } if (Directory.Exists(s_path) == false) { Directory.CreateDirectory(s_path); } web_資料夾.Navigate(s_path); }); Action <String> ac_切換 = new Action <String>((String x) => { }); c_分頁 = new C_頁籤拖曳(stackPanel_1); c_分頁.ac_change = ac_切換; c_分頁.ac_click = ac_點擊; c_右下角圖示 = new C_右下角圖示(this); c_右下角圖示.func_隱藏(); SET = new C_setting(this); SET.fun_開啟程式時讀取上次設定(0); //初始化分頁 func_分頁重新整理(true); //讓視窗可以拖曳 dockPanel_功能列.MouseLeftButtonDown += (sender, e) => { try { c_視窗改變大小.ResizeWindow(ResizeDirection.Move);//拖曳視窗 } catch { } }; lab_標題列.MouseLeftButtonDown += (sender, e) => { try { c_視窗改變大小.ResizeWindow(ResizeDirection.Move);//拖曳視窗 } catch { } }; scroll_分頁捲軸容器.MouseLeftButtonDown += (sender, e) => { var obj = e.OriginalSource; if (obj == scroll_分頁捲軸容器) { try { this.DragMove(); } catch { } } }; //雙擊全螢幕 dockPanel_功能列.MouseDoubleClick += (sender, e) => { if (e.RightButton == MouseButtonState.Pressed) { return; } var obj = e.OriginalSource; System.Console.WriteLine(obj); if (obj is Border || obj is System.Windows.Shapes.Path) { return; } if (WindowState != WindowState.Maximized) { WindowState = WindowState.Maximized; } else { WindowState = WindowState.Normal; } }; lab_標題列.MouseDoubleClick += (sender, e) => { if (e.RightButton == MouseButtonState.Pressed) { return; } if (WindowState != WindowState.Maximized) { WindowState = WindowState.Maximized; } else { WindowState = WindowState.Normal; } }; //讓工具列可以水平捲動 ((UIElement)dockPanel_功能列.Content).MouseWheel += new MouseWheelEventHandler((object sender, MouseWheelEventArgs e) => { int x = e.Delta; if (x > 0) { dockPanel_功能列.LineLeft(); } else { dockPanel_功能列.LineRight(); } }); but_截圖.Click += (sender, e) => { func_截圖(); }; but_清空.Click += (sender, e) => { func_刪除目前資料夾(); }; but_重新整理.Click += (sender, e) => { func_重新整理資料夾(); }; but_開啟資料夾.Click += (sender, e) => { func_開啟資料夾(); }; but_設定.Click += (sender, e) => { if (w_設定 != null) { w_設定.Close(); w_設定 = null; } w_設定 = new W_設定(this); w_設定.Topmost = this.Topmost; w_設定.Owner = this; w_設定.Show(); }; //鎖定視窗在最上層 but_鎖定視窗.Click += (sender, e) => { func_視窗最上層(this, "auto"); }; but_縮小至右下角.Click += (sender, e) => { func_縮小至右下角(true); }; //分頁容器的右鍵選單 var u_menu_分頁容器 = new U_menu(this); scroll_分頁捲軸容器.MouseRightButtonUp += (sender, e) => { if (e.OriginalSource == scroll_分頁捲軸容器) { u_menu_分頁容器.func_open_滑鼠旁邊(); } }; but_分頁_add.MouseRightButtonUp += (sender, e) => { u_menu_分頁容器.func_open_滑鼠旁邊(); }; u_menu_分頁容器.func_add_menu("重新整理", null, () => { func_分頁重新整理(); }); u_menu_分頁容器.func_add_menu("開啟資料夾位置", null, () => { try { System.Diagnostics.Process.Start("explorer.exe", "\"" + func_取得儲存根目錄().Replace("/", "\\") + "\""); } catch { } }); u_menu_分頁容器.func_add_menu("新增", null, () => { but_分頁_add_Click(null, null); }); this.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, this.OnCloseWindow)); this.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, this.OnMaximizeWindow, this.OnCanResizeWindow)); this.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, this.OnMinimizeWindow, this.OnCanMinimizeWindow)); this.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, this.OnRestoreWindow, this.OnCanResizeWindow)); this.Closing += (sender, e) => { if (Directory.Exists(func_exe_path() + "\\data") == false) { Directory.CreateDirectory(func_exe_path() + "\\data"); } SET.fun_儲存設定(); }; this.Loaded += MainWindow_Loaded; }