public C_按鈕選單_搜圖(MainWindow m) { this.M = m; u_menu_搜圖 = new U_menu(m); M.but_搜圖.Click += (sender, e) => { u_menu_搜圖.func_open(M.but_搜圖); }; u_menu_搜圖.func_add_menu("Google 搜圖", new BitmapImage(new Uri("/imgs/搜圖_google.png", UriKind.Relative)), () => { fun_執行搜圖("google"); }); u_menu_搜圖.func_add_menu("sauceNAO 搜圖", new BitmapImage(new Uri("/imgs/搜圖_sauceNAO.bmp", UriKind.Relative)), () => { fun_執行搜圖("saucenao"); }); u_menu_搜圖.func_add_menu("IQDB 搜圖", new BitmapImage(new Uri("/imgs/搜圖_IQDB.png", UriKind.Relative)), () => { fun_執行搜圖("iqdb"); }); u_menu_搜圖.func_add_menu("Ascii2d 搜圖", new BitmapImage(new Uri("/imgs/搜圖_ascii2d.bmp", UriKind.Relative)), () => { fun_執行搜圖("ascii2d"); }); }
/// <summary> /// /// </summary> /// <param name="m"></param> public C_旋轉(MainWindow m) { this.M = m; u_menu_旋轉 = new U_menu(m); M.but_旋轉.Click += (sender, e) => { u_menu_旋轉.func_open(M.but_旋轉); }; u_menu_旋轉.func_add_menu("順時針 90°", null, () => { func_旋轉_順時針_90(); }); u_menu_旋轉.func_add_menu("逆時針 90°", null, () => { func_旋轉_逆時針_90(); }); u_menu_旋轉.func_add_水平線(); u_menu_旋轉.func_add_menu("水平鏡像", null, () => { func_旋轉_水平(); }); u_menu_旋轉.func_add_menu("垂直鏡像", null, () => { func_旋轉_垂直(); }); u_menu_旋轉.func_add_水平線(); u_menu_旋轉.func_add_menu("初始化旋轉", null, () => { if (int_旋轉 == 270) { int_旋轉 = -90; } if (int_旋轉 == 360) { int_旋轉 = 0; } fun_旋轉動畫( M.grid_img, int_旋轉, 0, bool_水平鏡像, false, bool_垂直鏡像, false ); int_旋轉 = 0; bool_水平鏡像 = false; bool_垂直鏡像 = false; // fun_初始化旋轉(0); }); }
/// <summary> /// /// </summary> private void event_複製的選單() { u_menu_複製.func_add_menu("複製 檔案", null, () => { String s_path = M.ar_path[M.int_目前圖片位置]; //檔案或資料夾存在才複製 if (File.Exists(s_path) || Directory.Exists(s_path)) { var f = new System.Collections.Specialized.StringCollection(); f.Add(s_path); Clipboard.SetFileDropList(f); } }); u_menu_複製.func_add_menu("複製 檔名", null, () => { String s_path = M.ar_path[M.int_目前圖片位置]; s_path = s_path.Substring(s_path.LastIndexOf("\\") + 1); try { System.Windows.Forms.Clipboard.SetDataObject( s_path, //text to store in clipboard false, //do not keep after our app exits 5, //retry 5 times 200); //200ms delay between retries } catch { } }); u_menu_複製.func_add_menu("複製 完整路徑", null, () => { String s_path = M.ar_path[M.int_目前圖片位置]; try { System.Windows.Forms.Clipboard.SetDataObject( s_path, //text to store in clipboard false, //do not keep after our app exits 5, //retry 5 times 200); //200ms delay between retries } catch { } }); u_menu_複製.func_add_水平線(); propertyMenu_複製_影像 = u_menu_複製.func_add_menu("複製 影像", null, () => { try { fun_複製影像(); } catch (Exception e2) { MessageBox.Show(e2.ToString()); } }); propertyMenu_複製_png = u_menu_複製.func_add_menu("複製 PNG (低相容)", null, () => { String s_當前目錄 = M.ar_path[M.int_目前圖片位置]; if (File.Exists(s_當前目錄)) { try { System.Drawing.Bitmap bm_transparent = null; MemoryStream ms = new MemoryStream(); if (M.stackPlanel_動圖工具.Visibility == Visibility.Visible) //如果是動圖,就直接抓目前幀的圖片來處理 { BitmapEncoder enc = new PngBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(M.c_P網.fun_取得目前圖片())); enc.Save(ms); } else { String s_附檔名 = M.s_img_type_附檔名; if (s_附檔名 == "PSD" || s_附檔名 == "AI" || s_附檔名 == "PDF" || s_附檔名 == "WEBP") { using (var mi = M.c_影像.c_Magick.getImg(s_當前目錄, s_附檔名)) { bm_transparent = mi.ToBitmap(); } } else if (s_附檔名 == "EXE" || s_附檔名 == "LNK") { bm_transparent = M.c_影像.BitmapFromSource(M.c_P網.fun_取得exe圖示(s_當前目錄, s_附檔名)); } else { bm_transparent = new System.Drawing.Bitmap(s_當前目錄); } bm_transparent.Save(ms, System.Drawing.Imaging.ImageFormat.Png); } System.Windows.Forms.Clipboard.Clear();//先清理剪貼簿 System.Windows.Forms.IDataObject data_object = new System.Windows.Forms.DataObject(); data_object.SetData("PNG", false, ms); System.Windows.Forms.Clipboard.SetDataObject(data_object, false); } catch (Exception e2) { MessageBox.Show(e2.ToString()); } } }); propertyMenu_複製_svg = propertyMenu_複製_影像 = u_menu_複製.func_add_menu("複製 SVG (文字)", null, () => { String s_當前目錄 = M.ar_path[M.int_目前圖片位置]; try { if (File.Exists(s_當前目錄)) { using (StreamReader sr = new StreamReader(s_當前目錄, Encoding.UTF8)) { System.Windows.Forms.Clipboard.SetDataObject(sr.ReadToEnd(), false, 5, 200); } } } catch (Exception e2) { MessageBox.Show(e2.ToString()); } }); propertyMenu_複製_影像 = u_menu_複製.func_add_menu("複製 base64", null, () => { func_複製_base64(); }); }
/// <summary> /// /// </summary> private void event_其他程式啟動_選單(List <data_開啟程式> ar) { M.but_用外部程式開啟.Click += (sender, e) => { u_menu_用外部程式開啟.func_open(M.but_用外部程式開啟); }; u_menu_用外部程式開啟.func_add_menu("檔案右鍵選單", null, () => { fun_顯示原生右鍵選單(false); }); u_menu_用外部程式開啟.func_add_menu("開啟檔案位置", null, () => { M.fun_用檔案總管開啟目前圖片(); }); u_menu_用外部程式開啟.func_add_menu("列印", null, () => { try { var pr = new System.Diagnostics.Process(); pr.StartInfo.FileName = M.ar_path[M.int_目前圖片位置];//文件全稱-包括文件後綴 pr.StartInfo.CreateNoWindow = true; pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pr.StartInfo.Verb = "Print"; pr.Start(); } catch (Exception e2) { MessageBox.Show("找不到對應開啟的程式:\n" + e2.ToString(), "列印失敗"); } }); u_menu_用外部程式開啟.func_add_menu("設成桌布", null, () => { if (File.Exists(M.ar_path[M.int_目前圖片位置])) //判別檔案是否存在於對應的路徑 { try { SystemParametersInfo(20, 1, M.ar_path[M.int_目前圖片位置], 0x1 | 0x2); //存在成立,修改桌布 (uActuin 20 參數為修改wallpaper } catch (Exception e2) { MessageBox.Show("設定桌布失敗:\n" + e2.ToString(), "失敗"); } } }); u_menu_用外部程式開啟.func_add_menu("選擇其他程式", null, () => { if (File.Exists(M.ar_path[M.int_目前圖片位置])) //判別檔案是否存在於對應的路徑 { try { String _path = M.ar_path[M.int_目前圖片位置]; Process.Start(new ProcessStartInfo("rundll32.exe") { Arguments = $"shell32.dll,OpenAs_RunDLL {_path}", WorkingDirectory = Path.GetDirectoryName(_path) }); } catch (Exception e2) { MessageBox.Show(e2.ToString(), "Error"); } } }); u_menu_用外部程式開啟.func_add_水平線(); //使用者自定的名單 for (int i = 0; i < ar.Count; i++) { int xx = i; BitmapSource img = null; try { img = M.c_影像.BitmapToBitmapSource(ar[i].img); } catch { } u_menu_用外部程式開啟.func_add_menu(ar[i].name, img, () => { try { System.Diagnostics.Process.Start(ar[xx].path, "\"" + M.ar_path[M.int_目前圖片位置] + "\""); } catch (Exception e2) { MessageBox.Show(e2.ToString()); } }); }//for }
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; }