From 9d5ab28d963180f20cd40ab09e5d3504fba2af9b Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Mon, 1 Sep 2025 11:58:11 +0800 Subject: [PATCH] =?UTF-8?q?2509011155=20=E7=A8=8B=E5=BC=8F=E7=A2=BC?= =?UTF-8?q?=E9=87=8D=E6=A7=8B=20=E5=BA=A7=E6=A8=99=E8=B3=87=E6=96=99?= =?UTF-8?q?=E5=BE=9Eini=E4=BD=B5=E5=85=A5=E7=A8=8B=E5=BC=8F=E5=85=A7=20Med?= =?UTF-8?q?ia=E8=A8=AD=E5=AE=9A=E5=8F=83=E6=95=B8=E5=85=88=E5=B0=87clock?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E8=A8=BB=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...PrimaryForm.SingerSearch.BopomofoSearch.cs | 987 ++++-------------- .../PrimaryForm.SongSearch.BopomofoSearch.cs | 626 ++++------- Services/MediaService.cs | 6 +- img.ini | 87 -- 4 files changed, 409 insertions(+), 1297 deletions(-) diff --git a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs index a02ab96..1ce1963 100644 --- a/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs +++ b/PrimaryFormParts/SingerSearch/PrimaryForm.SingerSearch.BopomofoSearch.cs @@ -1,42 +1,222 @@ using System.IO; -using System.Drawing.Imaging; -using IniParser; -using IniParser.Model; -using System.Text; namespace DualScreenDemo { public partial class PrimaryForm { private PictureBox pictureBoxZhuYinSingers; - private Button[] phoneticButtonsForSingers; private Button modifyButtonZhuYinSingers; private Button clearButtonZhuYinSingers; private Button closeButtonZhuYinSingers; - - private string[] phoneticSymbols; - private (int X, int Y, int Width, int Height)[] phoneticButtonCoords; - private Dictionary phoneticButtonImages; - - private (int X, int Y, int Width, int Height) modifyButtonZhuYinCoords; - private (int X, int Y, int Width, int Height) clearButtonZhuYinCoords; - private (int X, int Y, int Width, int Height) closeButtonZhuYinCoords; - private RichTextBox inputBoxZhuYinSingers; - private (int X, int Y, int Width, int Height) inputBoxZhuYinCoords; - private string inputBoxFontName; - private float inputBoxFontSize; - private FontStyle inputBoxFontStyle; - private Color inputBoxForeColor; + private void InitializeButtonsForZhuYinSingers() + { + InitializePhoneticSymbolSingerBtns(pictureBoxZhuYinSingers, PhoneticButton_Click); + // 初始化注音歌手的輸入框 + InitializeInputBoxZhuYinSingers(); + InitializeBopomofoSingersButton(); + } + + + private void InitializeBopomofoSingersButton() + { + var data = LoadBtnConfigData(); + + modifyButtonZhuYinSingers = new Button { Name = "modifyButtonZhuYinSingers" }; + ConfigureButton(modifyButtonZhuYinSingers, 650, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["mouseDown"])), + ModifyButtonZhuYinSingers_Click); + + pictureBoxZhuYinSingers.Controls.Add(modifyButtonZhuYinSingers); + + + clearButtonZhuYinSingers = new Button { Name = "clearButtonZhuYinSingers" }; + ConfigureButton(clearButtonZhuYinSingers, 8, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["mouseDown"])), + ClearButtonZhuYinSingers_Click); + + pictureBoxZhuYinSingers.Controls.Add(clearButtonZhuYinSingers); + + + closeButtonZhuYinSingers = new Button { Name = "closeButtonZhuYinSingers" }; + ConfigureButton(closeButtonZhuYinSingers, 730, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["mouseDown"])), + CloseButtonZhuYinSingers_Click); + + pictureBoxZhuYinSingers.Controls.Add(closeButtonZhuYinSingers); + } + + private void InitializePhoneticSymbolSingerBtns(Control control, EventHandler handler) + { + phoneticButtonsForSingers = new Button[35]; + + // 設置上排按鈕 + int x = 8; + for (int i = 0; i < 10; i++) + { + CreatePhoneticSymbolSingerBtns(i, x, 65, control, handler); + x += 80; + } + + x = 8; + for (int i = 10; i < 20; i++) + { + CreatePhoneticSymbolSingerBtns(i, x, 135, control, handler); + x += 80; + } + + x = 40; + for (int i = 20; i < 29; i++) + { + CreatePhoneticSymbolSingerBtns(i, x, 205, control, handler); + x += 80; + } + // 設置下排按鈕 + x = 88; + for (int i = 29; i < 32; i++) + { + CreatePhoneticSymbolSingerBtns(i, x, 275, control, handler); + x += 80; + } + x += 80; + for (int i = 32; i < 35; i++) + { + CreatePhoneticSymbolSingerBtns(i, x, 275, control, handler); + x += 80; + } + } + + + private void CreatePhoneticSymbolSingerBtns(int index, int x, int y, Control control, EventHandler handler) + { + try + { + // 加載配置數據 + var data = LoadBtnConfigData(); + // 創建語音按鈕並設置其屬性 + phoneticButtonsForSingers[index] = new Button + { + Name = $"phoneticButtonsForSongs_{ButtonsPhoneticSymbols[index]}", // 按鈕名稱設為語音符號名稱 + }; + if (index == 31) + { + ConfigureButton(phoneticButtonsForSingers[index], x, y, 154, 67, + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_normal"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseDown"])), + handler); + } + else + { + ConfigureButton(phoneticButtonsForSingers[index], x, y, 72, 67, + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_normal"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseDown"])), + handler); + } + + + + // 設置按鈕的 Tag 屬性為對應的語音符號 + phoneticButtonsForSingers[index].Tag = ButtonsPhoneticSymbols[index]; + + // 將按鈕添加到表單的控制項集合中 + control.Controls.Add(phoneticButtonsForSingers[index]); + } + catch (Exception ex) + { + Console.WriteLine($"Error creating button at index {index}: {ex.Message}"); + } + } + + // 初始化 ZhuYin 歌手的輸入框,並設定其屬性與事件處理程序。 + private void InitializeInputBoxZhuYinSingers() + { + try + { + string fontName = "Times New Roman"; + float fontSize = 26; + FontStyle fontStyle = FontStyle.Regular; + Color foreColor = Color.Black; + + inputBoxZhuYinSingers = new RichTextBox + { + Name = "inputBoxZhuYinSongs", + ForeColor = foreColor, // 設定文字顏色 + Font = new Font(fontName, fontSize / 900 * Screen.PrimaryScreen.Bounds.Height, fontStyle), + ScrollBars = RichTextBoxScrollBars.None // 禁用滾動條 + }; + + // 調整和定位輸入框的位置及大小 + ResizeAndPositionControl(inputBoxZhuYinSingers, 10, 12, 455, 47); + + // 將輸入框加入到窗體的控件集合中 + pictureBoxZhuYinSingers.Controls.Add(inputBoxZhuYinSingers); + } + catch (Exception ex) + { + // 如果初始化過程中出現錯誤,則在控制台輸出錯誤信息 + Console.WriteLine("Error initializing inputBoxZhuYinSingers: " + ex.Message); + } + } + + // 顯示圖片並根據配置文件設置顯示區域的大小和位置。 + private void ShowImageOnPictureBoxZhuYinSingers(string imagePath) + { + // 加載原始圖片 + Bitmap originalImage = new Bitmap(imagePath); + + // 設置圖片到 PictureBox + pictureBoxZhuYinSingers.Image = originalImage; + + // 調整 PictureBox 大小和位置 + ResizeAndPositionPictureBox(pictureBoxZhuYinSingers, 390, 360, 808, 356); + + // 顯示圖片 + pictureBoxZhuYinSingers.Visible = true; + } + + + // 設置注音歌手相關控制項(包括圖片框、按鈕和輸入框)的顯示或隱藏狀態。 + private void SetZhuYinSingersAndButtonsVisibility(bool isVisible) + { + // 定義一個動作來處理控制項的顯示或隱藏 + System.Action action = () => + { + try + { + // 暫停控制項佈局的重新排版,提高效率 + SuspendLayout(); + if (isVisible) SetUIVisible(pictureBoxZhuYinSingers); + else CloseUI(pictureBoxZhuYinSingers); + ResumeLayout(); + PerformLayout(); + } + catch (Exception ex) + { + Console.WriteLine("Error in SetZhuYinSingersAndButtonsVisibility: " + ex.Message); + } + }; + + // 檢查是否需要在主執行緒外執行 + if (this.InvokeRequired) + { + this.Invoke(action); // 如果需要,透過主執行緒執行 + } + else + { + action(); // 否則直接執行 + } + } - /// - /// 點擊「注音歌手搜尋」按鈕時執行的事件處理函式。 - /// 此函式負責更新按鈕的背景圖片、載入對應的歌手圖片,並切換相關 UI 控件的可見性。 - /// - /// 觸發事件的物件(通常是按鈕本身)。 - /// 事件參數。 private void ZhuyinSearchSingersButton_Click(object sender, EventArgs e) { // 設定按鈕背景,將「注音搜尋」設為啟動狀態,其餘按鈕恢復為正常狀態 @@ -65,432 +245,22 @@ namespace DualScreenDemo // 顯示「注音歌手搜尋」的圖片框 pictureBoxZhuYinSingers.Visible = true; } - - - - /// - /// 從 config.ini 設定檔中載入注音符號(Phonetic Symbols)。 - /// 讀取 ini 檔的 [PhoneticSymbols] 區塊,並將「Symbols」欄位的值解析為陣列。 - /// - private void LoadPhoneticSymbolsFromConfig() - { - // 建立 INI 檔案解析器 - var parser = new FileIniDataParser(); - - // 設定檔路徑 - string iniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "img.ini"); - - - IniData data; - - // 以 UTF-8 編碼開啟並讀取 INI 檔案 - using (var reader = new StreamReader(iniFilePath, Encoding.UTF8)) - { - // 解析 INI 檔內容 - data = parser.ReadData(reader); - } - - // 取得 [PhoneticSymbols] 區塊中的 "Symbols" 欄位內容 - string symbols = data["PhoneticSymbols"]["Symbols"]; - - // 將符號字串以逗號分隔,轉換為字串陣列 - phoneticSymbols = symbols.Split(','); - } - - - /// - /// 從 INI 設定數據中讀取注音符號 (Phonetic Symbols)。 - /// - /// 已解析的 INI 設定數據。 - /// 回傳包含注音符號的字串陣列。 - private string[] LoadPhoneticSymbols(IniData data) - { - // 從 INI 檔案的 [PhoneticSymbols] 區塊取得 Symbols 欄位值 - string symbols = data["PhoneticSymbols"]["Symbols"]; - - // 以逗號分隔字串並轉換為字串陣列 - return symbols.Split(','); - } - - - /// - /// 從 INI 設定數據中載入按鈕座標資料。 - /// - /// 已解析的 INI 設定數據。 - /// 設定檔中按鈕座標所屬的區塊名稱。 - /// 按鈕數量。 - /// 回傳包含按鈕座標的陣列,每個元素是由 (X, Y, Width, Height) 組成的元組。 - private (int X, int Y, int Width, int Height)[] LoadButtonCoordinates(IniData data, string section, int buttonCount) - { - var buttonList = new List<(int X, int Y, int Width, int Height)>(); - - // 迴圈讀取每個按鈕的座標設定 - for (int i = 1; i <= buttonCount; i++) - { - // 取得按鈕座標的字串 (格式: X,Y,Width,Height) - var coordString = data[section][$"button{i}"]; - var coords = coordString.Split(','); - - // 將座標資料轉換為 (X, Y, Width, Height) 元組並加入清單 - buttonList.Add(( - int.Parse(coords[0]), // X 座標 - int.Parse(coords[1]), // Y 座標 - int.Parse(coords[2]), // 寬度 - int.Parse(coords[3]) // 高度 - )); - } - - // 回傳所有按鈕座標的陣列 - return buttonList.ToArray(); - } - - /// - /// 從 INI 設定數據中載入按鈕圖片檔案路徑資料 (包含正常、點擊、滑鼠移過圖片)。 - /// - /// 已解析的 INI 設定數據。 - /// 設定檔中按鈕圖片設定所屬的區塊名稱。 - /// 按鈕數量。 - /// 回傳一個字典,鍵是按鈕名稱,值是包含正常、點擊和滑鼠移過狀態的元組。 - private Dictionary LoadButtonImages(IniData data, string section, int buttonCount) - { - var buttonImages = new Dictionary(); - - // 迴圈讀取每個按鈕的圖片設定 - for (int i = 0; i < 35; i++) - { - // 讀取按鈕的三種圖片狀態:正常、點擊、滑鼠移過 - buttonImages[$"button{i}"] = ( - data[section][$"button{i}_normal"], // 正常狀態圖片路徑 - data[section][$"button{i}_mouseDown"], // 點擊狀態圖片路徑 - data[section][$"button{i}_mouseOver"] // 滑鼠移過狀態圖片路徑 - ); - } - - // 回傳包含所有按鈕圖片路徑資料的字典 - return buttonImages; - } - - - /// - /// 從 INI 設定數據中載入特定按鈕的座標資料。 - /// - /// 已解析的 INI 設定數據。 - /// 設定檔中按鈕座標所屬的區塊名稱。 - /// 指定按鈕的鍵名 (如 "button1")。 - /// 回傳包含按鈕座標的元組 (X, Y, Width, Height)。 - private (int X, int Y, int Width, int Height) LoadSpecialButtonCoordinates(IniData data, string section, string buttonKey) - { - // 取得按鈕座標的字串 (格式: X,Y,Width,Height) - var coords = data[section][buttonKey].Split(','); - - // 解析座標字串並回傳 (X, Y, Width, Height) 元組 - return (int.Parse(coords[0]), int.Parse(coords[1]), int.Parse(coords[2]), int.Parse(coords[3])); - } - - /// - /// 從 INI 設定數據中載入按鈕的圖片資料 (包含正常、點擊、滑鼠移過圖片)。 - /// - /// 已解析的 INI 設定數據。 - /// 設定檔中按鈕圖片設定所屬的區塊名稱。 - /// 回傳包含按鈕三種狀態圖片路徑的元組 (normal, mouseDown, mouseOver)。 - private (string normal, string mouseDown, string mouseOver) LoadButtonImages(IniData data, string section) - { - // 讀取按鈕三種狀態的圖片路徑 - return ( - data[section]["normal"], // 正常狀態圖片路徑 - data[section]["mouseDown"], // 點擊狀態圖片路徑 - data[section]["mouseOver"] // 滑鼠移過狀態圖片路徑 - ); - } - - - /// - /// 初始化並設置語音按鈕的相關資料,包括符號、座標與圖片等。 - /// - private void InitializePhoneticButtons() - { - // 載入配置資料 - var data = LoadBtnConfigData(); - - // 載入語音符號(如拼音、注音符號等) - phoneticSymbols = LoadPhoneticSymbols(data); - - // 載入按鈕座標資料 - phoneticButtonCoords = LoadButtonCoordinates(data, "PhoneticButtonCoordinates", 35); - - // 載入按鈕圖片資料 - phoneticButtonImages = LoadButtonImages(data, "PhoneticButtonImages", 35); - - // 初始化語音按鈕陣列,總共有 35 個按鈕 - phoneticButtonsForSingers = new Button[35]; - - // 設置每個語音按鈕 - for (int i = 0; i < 35; i++) - { - // 根據按鈕索引讀取其圖片資料 - var buttonImages = phoneticButtonImages[$"button{i}"]; - - // 創建並初始化語音按鈕,設定其背景圖片 - CreatePhoneticButton(i, buttonImages.normal, buttonImages.mouseDown, buttonImages.mouseOver); - } - } - - - /// - /// 創建一個語音按鈕,並為其設置圖片、座標、事件等屬性。 - /// - /// 按鈕的索引,用來獲取對應的語音符號、座標和圖片資料。 - /// 正常狀態下的圖片路徑。 - /// 點擊狀態下的圖片路徑。 - /// 滑鼠移過狀態下的圖片路徑。 - private void CreatePhoneticButton(int index, string normalImagePath, string mouseDownImagePath, string mouseOverImagePath) - { - try - { - // 創建語音按鈕並設置其屬性 - phoneticButtonsForSingers[index] = new Button - { - Name = $"phoneticButton_{phoneticSymbols[index]}", // 按鈕名稱設為語音符號名稱 - BackgroundImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)), // 設定背景圖片 - BackgroundImageLayout = ImageLayout.Stretch, // 設定圖片拉伸樣式 - FlatStyle = FlatStyle.Flat, // 設定為平面風格 - FlatAppearance = { BorderSize = 0 } // 設定無邊框 - }; - - // 調整按鈕大小並設置位置 - ResizeAndPositionButton(phoneticButtonsForSingers[index], phoneticButtonCoords[index].X, phoneticButtonCoords[index].Y, - phoneticButtonCoords[index].Width, phoneticButtonCoords[index].Height); - - // 從檔案中讀取正常、點擊和滑鼠懸停狀態的圖片 - Image normalImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)); - Image mouseDownImage = Image.FromFile(Path.Combine(serverPath, mouseDownImagePath)); - Image mouseOverImage = Image.FromFile(Path.Combine(serverPath, mouseOverImagePath)); - - // 設置滑鼠事件:點擊、進入、離開等,改變按鈕的背景圖片 - phoneticButtonsForSingers[index].MouseDown += (s, e) => phoneticButtonsForSingers[index].BackgroundImage = mouseDownImage; - phoneticButtonsForSingers[index].MouseUp += (s, e) => phoneticButtonsForSingers[index].BackgroundImage = normalImage; - phoneticButtonsForSingers[index].MouseEnter += (s, e) => phoneticButtonsForSingers[index].BackgroundImage = mouseOverImage; - phoneticButtonsForSingers[index].MouseLeave += (s, e) => phoneticButtonsForSingers[index].BackgroundImage = normalImage; - - // 設置點擊事件處理方法 - phoneticButtonsForSingers[index].Click += PhoneticButton_Click; - - // 設置按鈕的 Tag 屬性為對應的語音符號 - phoneticButtonsForSingers[index].Tag = phoneticSymbols[index]; - - // 將按鈕添加到表單的控制項集合中 - this.Controls.Add(phoneticButtonsForSingers[index]); - } - catch (Exception ex) - { - // 捕捉錯誤並輸出錯誤訊息 - Console.WriteLine($"Error creating button at index {index}: {ex.Message}"); - } - } - - - /// - /// 初始化所有與注音歌手相關的按鈕,包括語音符號按鈕、特殊按鈕及輸入框。 - /// - private void InitializeButtonsForZhuYinSingers() - { - // 從配置檔案加載注音符號並初始化按鈕 - LoadPhoneticSymbolsFromConfig(); - - // 初始化所有語音按鈕 - InitializePhoneticButtons(); - - // 初始化注音歌手的特殊按鈕(例如音量、搜尋等) - InitializeSpecialButtonsForZhuYinSingers(); - - // 初始化注音歌手的輸入框 - InitializeInputBoxZhuYinSingers(); - } - - - /// - /// 移除圖像周圍的白色邊框,將邊框的像素透明化。 - /// - /// 待處理的圖像文件路徑。 - /// 處理後的圖像,其中白色邊框已被去除並替換為透明。 - private Image RemoveWhiteBorder(string imagePath) - { - // 創建一個 Bitmap 物件來加載圖像 - Bitmap bmp = new Bitmap(imagePath); - - // 定義圖像的矩形區域,這是我們將要操作的區域 - Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); - - // 鎖定圖像的位圖數據,以便進行直接修改 - BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat); - - IntPtr ptr = bmpData.Scan0; // 獲取位圖數據的起始位置 - int bytes = Math.Abs(bmpData.Stride) * bmp.Height; // 計算圖像的總字節數 - byte[] rgbValues = new byte[bytes]; // 用來存儲圖像的像素數據 - System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); // 從圖像數據中複製像素數據到 rgbValues 陣列 - - // 遍歷每個像素點,檢查是否為白色邊框 - for (int y = 0; y < bmp.Height; y++) - { - for (int x = 0; x < bmp.Width; x++) - { - int position = (y * bmpData.Stride) + (x * 4); // 計算當前像素的位址 - byte b = rgbValues[position]; // 藍色分量 - byte g = rgbValues[position + 1]; // 綠色分量 - byte r = rgbValues[position + 2]; // 紅色分量 - byte a = rgbValues[position + 3]; // alpha 分量(透明度) - - // 如果當前像素在圖像邊緣且為白色 (255, 255, 255),則將其設為透明 - if ((x < 5 || x > bmp.Width - 5 || y < 5 || y > bmp.Height - 5) && r == 255 && g == 255 && b == 255) - { - // 將白色像素的 RGB 設置為 255, 255, 255 且 alpha 設為 0 (透明) - rgbValues[position] = 255; - rgbValues[position + 1] = 255; - rgbValues[position + 2] = 255; - rgbValues[position + 3] = 0; // 透明 - } - } - } - - // 將修改後的像素數據重新複製回位圖數據 - System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); - - // 解鎖圖像數據 - bmp.UnlockBits(bmpData); - - // 返回處理後的圖像 - return bmp; - } - - - /// - /// 初始化與注音歌手相關的特殊按鈕,包括修改、清除和關閉按鈕。 - /// - private void InitializeSpecialButtonsForZhuYinSingers() - { - // 初始化修改按鈕 - InitializeModifyButtonZhuYinSingers(); - - // 初始化清除按鈕 - InitializeClearButtonZhuYinSingers(); - - // 初始化關閉按鈕 - InitializeCloseButtonZhuYinSingers(); - } - - - /// - /// 初始化「修改」按鈕,設定按鈕的坐標、圖片和點擊事件。 - /// - private void InitializeModifyButtonZhuYinSingers() - { - // 加載配置數據 - var data = LoadBtnConfigData(); - - // 讀取按鈕坐標 - modifyButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "modifyButtonZhuYinSingers"); - - // 加載按鈕圖片(正常、鼠標懸停、鼠標按下) - var buttonImages = LoadButtonImages(data, "ModifyButtonImagesZhuYin"); - - // 創建「修改」按鈕,並設置坐標、圖片及點擊事件 - modifyButtonZhuYinSingers = CreateSpecialButton( - "btnModifyZhuYinSingers", // 按鈕名稱 - modifyButtonZhuYinCoords, // 按鈕坐標 - buttonImages.normal, // 正常狀態圖片 - buttonImages.mouseOver, // 鼠標懸停圖片 - buttonImages.mouseDown, // 鼠標按下圖片 - ModifyButtonZhuYinSingers_Click // 按鈕點擊事件 - ); - } - - /// - /// 處理「修改」按鈕的點擊事件,該事件會刪除輸入框中的最後一個字符。 - /// - /// 觸發事件的對象 - /// 事件參數 private void ModifyButtonZhuYinSingers_Click(object sender, EventArgs e) { // 如果輸入框不為空,且包含輸入內容,則刪除最後一個字符 - if (this.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0) + if (pictureBoxZhuYinSingers.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0) { inputBoxZhuYinSingers.Text = inputBoxZhuYinSingers.Text.Substring(0, inputBoxZhuYinSingers.Text.Length - 1); } - } - - - /// - /// 初始化「清除」按鈕,設定按鈕的坐標、圖片和點擊事件。 - /// - private void InitializeClearButtonZhuYinSingers() - { - // 加載配置數據 - var data = LoadBtnConfigData(); - - // 讀取按鈕坐標 - clearButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "clearButtonZhuYinSingers"); - - // 加載按鈕圖片(正常、鼠標懸停、鼠標按下) - var buttonImages = LoadButtonImages(data, "ClearButtonImagesZhuYin"); - - // 創建「清除」按鈕,並設置坐標、圖片及點擊事件 - clearButtonZhuYinSingers = CreateSpecialButton( - "btnClearZhuYinSingers", // 按鈕名稱 - clearButtonZhuYinCoords, // 按鈕坐標 - buttonImages.normal, // 正常狀態圖片 - buttonImages.mouseOver, // 鼠標懸停圖片 - buttonImages.mouseDown, // 鼠標按下圖片 - ClearButtonZhuYinSingers_Click // 按鈕點擊事件 - ); - } - - /// - /// 處理「清除」按鈕的點擊事件,該事件會清空輸入框中的所有文本。 - /// - /// 觸發事件的對象 - /// 事件參數 + } private void ClearButtonZhuYinSingers_Click(object sender, EventArgs e) { // 如果輸入框不為空,則清空該框的文本內容 - if (this.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0) + if (pictureBoxZhuYinSingers.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0) { inputBoxZhuYinSingers.Text = ""; } } - - - /// - /// 初始化「關閉」按鈕,設定按鈕的坐標、圖片和點擊事件。 - /// - private void InitializeCloseButtonZhuYinSingers() - { - // 加載配置數據 - var data = LoadBtnConfigData(); - - // 讀取按鈕坐標 - closeButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "closeButtonZhuYinSingers"); - - // 加載按鈕圖片(正常、鼠標懸停、鼠標按下) - var buttonImages = LoadButtonImages(data, "CloseButtonImagesZhuYin"); - - // 創建「關閉」按鈕,並設置坐標、圖片及點擊事件 - closeButtonZhuYinSingers = CreateSpecialButton( - "btnCloseZhuYinSingers", // 按鈕名稱 - closeButtonZhuYinCoords, // 按鈕坐標 - buttonImages.normal, // 正常狀態圖片 - buttonImages.mouseOver, // 鼠標懸停圖片 - buttonImages.mouseDown, // 鼠標按下圖片 - CloseButtonZhuYinSingers_Click // 按鈕點擊事件 - ); - } - - - /// - /// 「關閉」按鈕的點擊事件處理方法。 - /// 隱藏 ZhuYin 歌手圖片框以及與其相關的按鈕。 - /// - /// 觸發事件的對象,這裡是關閉按鈕。 - /// 事件參數。 private void CloseButtonZhuYinSingers_Click(object sender, EventArgs e) { // 隱藏 ZhuYin 歌手圖片框 @@ -501,338 +271,21 @@ namespace DualScreenDemo // 隱藏與 ZhuYin 歌手相關的所有按鈕 SetZhuYinSingersAndButtonsVisibility(false); } - private void FindZhuYiSingers(){ - string searchText = inputBoxZhuYinSingers.Text; - string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM artists LIMIT 1000;" - : $"SELECT * FROM artists WHERE `phonetic_abbr` LIKE '{searchText}%';"; - //string query = $"SELECT * FROM ArtistLibrary WHERE `歌手注音` LIKE '{searchText}%' "; - var searchResults = SearchSingers_Mysql(query); - - currentPage = 0; - currentArtistList = searchResults; - totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - - multiPagePanel.currentPageIndex = 0; - multiPagePanel.LoadSingers(currentArtistList); - } - - /// - /// 創建一個特殊的按鈕,並設定其顯示屬性、事件處理和位置。 - /// - /// 按鈕的名稱。 - /// 按鈕的坐標和大小,包含 X, Y, 寬度和高度。 - /// 按鈕正常狀態下的背景圖片路徑。 - /// 鼠標懸停時按鈕的背景圖片路徑。 - /// 鼠標點擊時按鈕的背景圖片路徑。 - /// 按鈕的點擊事件處理程序。 - /// 創建並返回的按鈕對象。 - private Button CreateSpecialButton(string name, (int X, int Y, int Width, int Height) coords, string normalImagePath, string mouseOverImagePath, string mouseDownImagePath, EventHandler clickEventHandler) + private void FindZhuYiSingers() { - // 創建按鈕並設定基本屬性 - var button = new Button - { - Name = name, - FlatStyle = FlatStyle.Flat, - FlatAppearance = { BorderSize = 0, MouseDownBackColor = Color.Transparent, MouseOverBackColor = Color.Transparent }, - BackgroundImageLayout = ImageLayout.Stretch, - BackgroundImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)) - }; + string searchText = inputBoxZhuYinSingers.Text; + string query = string.IsNullOrWhiteSpace(searchText) + ? "SELECT * FROM artists LIMIT 1000;" + : $"SELECT * FROM artists WHERE `phonetic_abbr` LIKE '{searchText}%';"; + //string query = $"SELECT * FROM ArtistLibrary WHERE `歌手注音` LIKE '{searchText}%' "; + var searchResults = SearchSingers_Mysql(query); - // 設定按鈕的大小和位置 - ResizeAndPositionButton(button, coords.X, coords.Y, coords.Width, coords.Height); + currentPage = 0; + currentArtistList = searchResults; + totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - // 設定鼠標事件:進入、離開、按下、放開 - button.MouseEnter += (sender, e) => button.BackgroundImage = Image.FromFile(Path.Combine(serverPath, mouseOverImagePath)); - button.MouseLeave += (sender, e) => button.BackgroundImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)); - button.MouseDown += (sender, e) => button.BackgroundImage = Image.FromFile(Path.Combine(serverPath, mouseDownImagePath)); - button.MouseUp += (sender, e) => button.BackgroundImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)); - - // 註冊點擊事件處理 - button.Click += clickEventHandler; - - // 將按鈕添加到控件集合中 - this.Controls.Add(button); - - return button; - } - - - /// - /// 初始化 ZhuYin 歌手的輸入框,並設定其屬性與事件處理程序。 - /// - private void InitializeInputBoxZhuYinSingers() - { - try - { - // 加載輸入框配置 - LoadInputBoxConfig(); - - // 創建一個 RichTextBox 控件來作為輸入框 - inputBoxZhuYinSingers = new RichTextBox - { - Name = "inputBoxZhuYinSingers", - ForeColor = inputBoxForeColor, // 設定文字顏色 - Font = new Font(inputBoxFontName, inputBoxFontSize, inputBoxFontStyle), // 設定字體樣式 - ScrollBars = RichTextBoxScrollBars.None // 不顯示滾動條 - }; - - // 調整和定位輸入框的位置及大小 - ResizeAndPositionControl(inputBoxZhuYinSingers, inputBoxZhuYinCoords.X, inputBoxZhuYinCoords.Y, inputBoxZhuYinCoords.Width, inputBoxZhuYinCoords.Height); - - // 設定文本變更事件,當輸入框內容改變時觸發 - /*inputBoxZhuYinSingers.TextChanged += (sender, e) => - { - string searchText = inputBoxZhuYinSingers.Text; - - // 使用注音符號開頭的歌手名稱進行搜索 - var searchResults = allArtists.Where(artist => artist.Phonetic.StartsWith(searchText)).ToList(); - - // 使用注音符號包含的歌手名稱進行搜索 - currentPage = 0; - currentArtistList = searchResults; - totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - - multiPagePanel.currentPageIndex = 0; - multiPagePanel.LoadSingers(currentArtistList); - };*/ - - // 將輸入框加入到窗體的控件集合中 - this.Controls.Add(inputBoxZhuYinSingers); - } - catch (Exception ex) - { - // 如果初始化過程中出現錯誤,則在控制台輸出錯誤信息 - Console.WriteLine("Error initializing inputBoxZhuYinSingers: " + ex.Message); - } - } - - - /// - /// 從配置文件 `config.ini` 中加載輸入框的設置,包括位置、大小、字體等屬性。 - /// - private void LoadInputBoxConfig() - { - try - { - // 創建 INI 解析器 - var parser = new FileIniDataParser(); - string iniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "img.ini"); - - - IniData data; - // 打開並讀取配置文件 - using (var reader = new StreamReader(iniFilePath, Encoding.UTF8)) - { - data = parser.ReadData(reader); - } - - // 從配置中加載輸入框的坐標和大小 - inputBoxZhuYinCoords = ( - int.Parse(data["InputBoxZhuYinSingers"]["X"]), // 輸入框的 X 坐標 - int.Parse(data["InputBoxZhuYinSingers"]["Y"]), // 輸入框的 Y 坐標 - int.Parse(data["InputBoxZhuYinSingers"]["Width"]), // 輸入框的寬度 - int.Parse(data["InputBoxZhuYinSingers"]["Height"]) // 輸入框的高度 - ); - - // 從配置中加載字體屬性 - inputBoxFontName = data["InputBoxZhuYinSingers"]["FontName"]; // 字體名稱 - inputBoxFontSize = float.Parse(data["InputBoxZhuYinSingers"]["FontSize"]); // 字體大小 - Screen screen = Screen.PrimaryScreen; - int screenWidth = screen.Bounds.Width; - int screenHeight = screen.Bounds.Height; - if (screenWidth < 1920 && screenHeight < 1080) - { - inputBoxFontSize = 22; - } - inputBoxFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), data["InputBoxZhuYinSingers"]["FontStyle"]); // 字體樣式 - inputBoxForeColor = Color.FromName(data["InputBoxZhuYinSingers"]["ForeColor"]); // 字體顏色 - - } - catch (Exception ex) - { - // 若發生錯誤,顯示錯誤信息 - Console.WriteLine("Error loading inputBox configuration: " + ex.Message); - } - } - - - /// - /// 存儲 `pictureBoxZhuYinSingers` 控制項的坐標和大小設置。 - /// - /// - /// 這個元組包含了 `X`、`Y` 坐標以及 `Width`、`Height` 大小,用於配置 `pictureBoxZhuYinSingers` 的位置和大小。 - /// - private (int X, int Y, int Width, int Height) pictureBoxZhuYinSingerCoords; - - /// - /// 從配置檔案中讀取 `PictureBoxZhuYinSingers` 控制項的坐標和大小設置。 - /// - private void LoadPictureBoxZhuYinSingerCoordsFromConfig() - { - var parser = new FileIniDataParser(); - string iniPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "img.ini"); - IniData data = parser.ReadFile(iniPath); - - var coords = data["PictureBoxZhuYinSingers"]; - pictureBoxZhuYinSingerCoords = ( - int.Parse(coords["X"]), - int.Parse(coords["Y"]), - int.Parse(coords["Width"]), - int.Parse(coords["Height"]) - ); - } - - - /// - /// 顯示圖片並根據配置文件設置顯示區域的大小和位置。 - /// - /// 圖片的路徑。 - private void ShowImageOnPictureBoxZhuYinSingers(string imagePath) - { - // 讀取配置文件中的顯示區域設置 - LoadPictureBoxZhuYinSingerCoordsFromConfig(); - - // 加載原始圖片 - Bitmap originalImage = new Bitmap(imagePath); - - // 創建顯示區域,根據配置文件中的坐標和大小設置 - Rectangle displayArea = new Rectangle(pictureBoxZhuYinSingerCoords.X, pictureBoxZhuYinSingerCoords.Y, pictureBoxZhuYinSingerCoords.Width, pictureBoxZhuYinSingerCoords.Height); - - // 設置圖片到 PictureBox - pictureBoxZhuYinSingers.Image = originalImage; - - // 調整 PictureBox 大小和位置 - ResizeAndPositionPictureBox(pictureBoxZhuYinSingers, displayArea.X, displayArea.Y, displayArea.Width, displayArea.Height); - - // 顯示圖片 - pictureBoxZhuYinSingers.Visible = true; - } - - - /// - /// 設置注音歌手相關控制項(包括圖片框、按鈕和輸入框)的顯示或隱藏狀態。 - /// - /// 指定控件是否可見。True 為顯示,False 為隱藏。 - private void SetZhuYinSingersAndButtonsVisibility(bool isVisible) - { - // 定義一個動作來處理控制項的顯示或隱藏 - System.Action action = () => - { - try - { - // 暫停控制項佈局的重新排版,提高效率 - SuspendLayout(); - - // 檢查並設置圖片框的可見性 - if (pictureBoxZhuYinSingers == null) - { - Console.WriteLine("pictureBoxZhuYinSingers is null"); - } - else - { - pictureBoxZhuYinSingers.Visible = isVisible; - if (isVisible) pictureBoxZhuYinSingers.BringToFront(); // 如果顯示,將其置於最前 - } - - // 檢查並設置拼音按鈕的可見性 - if (phoneticButtonsForSingers == null) - { - Console.WriteLine("phoneticButtonsForSingers is null"); - } - else - { - foreach (var button in phoneticButtonsForSingers) - { - if (button == null) - { - Console.WriteLine("One of the phoneticButtonsForSingers is null"); - } - else - { - button.Visible = isVisible; - if (isVisible) button.BringToFront(); // 如果顯示,將其置於最前 - } - } - } - - // 檢查並設置修改按鈕的可見性 - if (modifyButtonZhuYinSingers == null) - { - Console.WriteLine("modifyButtonZhuYinSingers is null"); - } - else - { - modifyButtonZhuYinSingers.Visible = isVisible; - if (isVisible) modifyButtonZhuYinSingers.BringToFront(); // 如果顯示,將其置於最前 - } - - // 檢查並設置清除按鈕的可見性 - if (clearButtonZhuYinSingers == null) - { - Console.WriteLine("clearButtonZhuYinSingers is null"); - } - else - { - clearButtonZhuYinSingers.Visible = isVisible; - if (isVisible) clearButtonZhuYinSingers.BringToFront(); // 如果顯示,將其置於最前 - } - - // 檢查並設置關閉按鈕的可見性 - if (closeButtonZhuYinSingers == null) - { - Console.WriteLine("closeButtonZhuYinSingers is null"); - } - else - { - closeButtonZhuYinSingers.Visible = isVisible; - if (isVisible) closeButtonZhuYinSingers.BringToFront(); // 如果顯示,將其置於最前 - } - - // 檢查並設置輸入框的可見性 - if (inputBoxZhuYinSingers == null) - { - Console.WriteLine("inputBoxZhuYinSingers is null"); - } - else - { - inputBoxZhuYinSingers.Visible = isVisible; - if (isVisible) inputBoxZhuYinSingers.BringToFront(); // 如果顯示,將其置於最前 - } - - // 恢復控制項的佈局重新排版 - ResumeLayout(); - PerformLayout(); - - // 刷新所有控制項的顯示 - pictureBoxZhuYinSingers?.Refresh(); - if (phoneticButtonsForSingers != null) - { - foreach (var button in phoneticButtonsForSingers) - { - button?.Refresh(); // 刷新每個按鈕 - } - } - modifyButtonZhuYinSingers?.Refresh(); - clearButtonZhuYinSingers?.Refresh(); - closeButtonZhuYinSingers?.Refresh(); - inputBoxZhuYinSingers?.Refresh(); - } - catch (Exception ex) - { - Console.WriteLine("Error in SetZhuYinSingersAndButtonsVisibility: " + ex.Message); - } - }; - - // 檢查是否需要在主執行緒外執行 - if (this.InvokeRequired) - { - this.Invoke(action); // 如果需要,透過主執行緒執行 - } - else - { - action(); // 否則直接執行 - } + multiPagePanel.currentPageIndex = 0; + multiPagePanel.LoadSingers(currentArtistList); } } diff --git a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs index 61594c6..7d7b927 100644 --- a/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs +++ b/PrimaryFormParts/SongSearch/PrimaryForm.SongSearch.BopomofoSearch.cs @@ -1,8 +1,5 @@ using System.IO; -using IniParser; -using IniParser.Model; -/* Song Search with ZhuYin */ namespace DualScreenDemo { public partial class PrimaryForm @@ -12,424 +9,192 @@ namespace DualScreenDemo //存放注音按鈕的陣列 private Button[] phoneticButtonsForSongs; //特殊功能按鈕(修改、清除、關閉) + private string[] ButtonsPhoneticSymbols = ["ㄅ","ㄉ","ㄍ","ㄐ","ㄓ","ㄗ","ㄛ","ㄡ","ㄤ","ㄧ", + "ㄆ","ㄊ","ㄎ","ㄑ","ㄔ","ㄘ","ㄜ","ㄢ","ㄦ","ㄨ", + "ㄇ","ㄋ","ㄏ","ㄒ","ㄕ","ㄙ","ㄞ","ㄣ","ㄩ", + "ㄈ","ㄌ","","ㄖ","ㄚ","ㄠ"]; private Button modifyButtonZhuYinSongs; private Button clearButtonZhuYinSongs; private Button closeButtonZhuYinSongs; //用於顯示輸入文字的輸入框 private RichTextBox inputBoxZhuYinSongs; - /// - /// 注音歌曲搜尋按鈕點擊事件 - /// - private void ZhuyinSearchSongsButton_Click(object sender, EventArgs e) - { - //更新搜尋模式按鈕的背景圖 - UpdateSongSearchBtn(zhuyinSearchSongButton,zhuyinSearchSongActiveBackground); - // 讀取 config.ini 並獲取注音圖片的路徑 - var configData = LoadBtnConfigData(); - string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["ZhuYinSongs"]); - //顯示注音歌曲圖片 - ShowImageOnPictureBoxZhuYinSongs(Path.Combine(serverPath, imagePath)); - - - //設定不同模式的UI顯示 - SetWordCountSongsAndButtonsVisibility(false); // 隱藏字數搜尋相關控件 - SetEnglishSongsAndButtonsVisibility(false); - SetPinYinSongsAndButtonsVisibility(false); - SetHandWritingForSongsAndButtonsVisibility(false); - SetSongIDSearchAndButtonsVisibility(false); - SetZhuYinSongsAndButtonsVisibility(true); - ResetinputBox(); - pictureBoxZhuYinSongs.Visible = true; - } - /// - /// 初始化注音按鈕 (Phonetic Buttons) 並載入其對應的圖片與座標 - /// 1. 讀取 config.ini 設定檔,獲取按鈕的相關數據 (符號、座標、圖片) - /// 2. 解析注音符號並儲存至 phoneticSymbols 陣列 - /// 3. 解析按鈕的座標資訊,存入 phoneticButtonCoords - /// 4. 解析按鈕的圖片 (正常狀態、按下狀態、懸停狀態),存入 phoneticButtonImages。 - /// 5. 依序建立 35 個注音按鈕,並套用對應的圖片與事件處理函數。 - /// - private void InitializePhoneticButtonsForSongs() + private void InitializeButtonsForZhuYinSongs() + { + + // 4. 初始化輸入框 (用於顯示使用者輸入的注音符號) + InitializeInputBoxZhuYinSongs(); + InitializeBopomofoSongsButton(); + InitializePhoneticSymbolBtns(pictureBoxZhuYinSongs,PhoneticButton_Click); + } + + private void InitializeBopomofoSongsButton() { - // 1. 從設定檔 (config.ini) 讀取配置數據,包含按鈕座標、圖片等 var data = LoadBtnConfigData(); - // 2. 讀取注音符號列表,這些符號將用於顯示在按鈕上 - phoneticSymbols = LoadPhoneticSymbols(data); + modifyButtonZhuYinSongs = new Button { Name = "modifyButtonZhuYinSongs" }; + ConfigureButton(modifyButtonZhuYinSongs, 650, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesZhuYin"]["mouseDown"])), + ModifyButtonZhuYinSongs_Click); - // 3. 從設定檔載入 **注音按鈕的座標**,每個按鈕都有對應的 (X, Y, Width, Height) - phoneticButtonCoords = LoadButtonCoordinates(data, "PhoneticButtonCoordinates", 35); + pictureBoxZhuYinSongs.Controls.Add(modifyButtonZhuYinSongs); - // 4. 從設定檔載入 **注音按鈕的圖片**,每個按鈕都有正常、按下、懸停三種狀態 - phoneticButtonImages = LoadButtonImages(data, "PhoneticButtonImages", 35); - // 5. 建立 35 個注音按鈕的陣列 (每個按鈕對應一個注音符號) + clearButtonZhuYinSongs = new Button { Name = "clearButtonZhuYinSongs" }; + ConfigureButton(clearButtonZhuYinSongs, 8, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesZhuYin"]["mouseDown"])), + ClearButtonZhuYinSongs_Click); + + pictureBoxZhuYinSongs.Controls.Add(clearButtonZhuYinSongs); + + + closeButtonZhuYinSongs = new Button { Name = "closeButtonZhuYinSongs" }; + ConfigureButton(closeButtonZhuYinSongs, 730, 275, 72, 67, + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["normal"])), + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesZhuYin"]["mouseDown"])), + CloseButtonZhuYinSongs_Click); + + pictureBoxZhuYinSongs.Controls.Add(closeButtonZhuYinSongs); + } + + + private void InitializePhoneticSymbolBtns(Control control, EventHandler handler) + { phoneticButtonsForSongs = new Button[35]; - // 6. 迴圈建立所有的注音按鈕 - for (int i = 0; i < 35; i++) + // 設置上排按鈕 + int x = 8; + for (int i = 0; i < 10; i++) { - // 取得當前按鈕的圖片 (從已載入的 phoneticButtonImages 字典中獲取) - var buttonImages = phoneticButtonImages[$"button{i}"]; + CreatePhoneticSymbolBtns(i, x, 65, control, handler); + x += 80; + } - // 建立單個注音按鈕,並設定其圖片與點擊事件 - CreatePhoneticButtonForSongs( - i, // 按鈕索引 (對應於 phoneticSymbols) - buttonImages.normal, // 按鈕的普通狀態圖片 - buttonImages.mouseDown, // 按下時的圖片 - buttonImages.mouseOver // 滑鼠懸停時的圖片 - ); + x = 8; + for (int i = 10; i < 20; i++) + { + CreatePhoneticSymbolBtns(i, x, 135, control, handler); + x += 80; + } + + x = 40; + for (int i = 20; i < 29; i++) + { + CreatePhoneticSymbolBtns(i, x, 205, control, handler); + x += 80; + } + // 設置下排按鈕 + x = 88; + for (int i = 29; i < 32; i++) + { + CreatePhoneticSymbolBtns(i, x, 275, control, handler); + x += 80; + } + x += 80; + for (int i = 32; i < 35; i++) + { + CreatePhoneticSymbolBtns(i, x, 275, control, handler); + x += 80; } } - /// - /// 建立單個注音按鈕,並設定其圖片、大小、位置,以及滑鼠事件。 - /// - /// 按鈕索引 (對應於 phoneticSymbols) - /// 按鈕的普通狀態圖片路徑 - /// 按鈕被按下時的圖片路徑 - /// 滑鼠懸停時的圖片路徑 - private void CreatePhoneticButtonForSongs(int index, string normalImagePath, string mouseDownImagePath, string mouseOverImagePath) + private void CreatePhoneticSymbolBtns(int index, int x, int y, Control control, EventHandler handler) { try { - // 1. 創建按鈕並初始化屬性 + // 加載配置數據 + var data = LoadBtnConfigData(); + // 創建語音按鈕並設置其屬性 phoneticButtonsForSongs[index] = new Button { - Name = $"phoneticButton_{phoneticSymbols[index]}", // 設定按鈕名稱,方便識別 - BackgroundImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)), // 設定預設背景圖 - BackgroundImageLayout = ImageLayout.Stretch, // 背景圖自動填滿按鈕 - FlatStyle = FlatStyle.Flat, // 設定按鈕為扁平樣式 - FlatAppearance = { BorderSize = 0 } // 移除按鈕的邊框 + Name = $"phoneticButtonsForSongs_{ButtonsPhoneticSymbols[index]}", // 按鈕名稱設為語音符號名稱 }; + if (index == 31) + { + ConfigureButton(phoneticButtonsForSongs[index], x, y, 154, 67, + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_normal"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseDown"])), + handler); + } + else + { + ConfigureButton(phoneticButtonsForSongs[index], x, y, 72, 67, + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_normal"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseOver"])), + new Bitmap(Path.Combine(serverPath, data["PhoneticButtonImages"][$"button{index}_mouseDown"])), + handler); + } - // 2. 設定按鈕的大小與位置 - ResizeAndPositionButton( - phoneticButtonsForSongs[index], - phoneticButtonCoords[index].X, - phoneticButtonCoords[index].Y, - phoneticButtonCoords[index].Width, - phoneticButtonCoords[index].Height - ); - // 3. 載入三種狀態的圖片 - Image normalImage = Image.FromFile(Path.Combine(serverPath, normalImagePath)); - Image mouseDownImage = Image.FromFile(Path.Combine(serverPath, mouseDownImagePath)); - Image mouseOverImage = Image.FromFile(Path.Combine(serverPath, mouseOverImagePath)); - // 4. 設定滑鼠事件,改變背景圖 - phoneticButtonsForSongs[index].MouseDown += (s, e) => phoneticButtonsForSongs[index].BackgroundImage = mouseDownImage; - phoneticButtonsForSongs[index].MouseUp += (s, e) => phoneticButtonsForSongs[index].BackgroundImage = normalImage; - phoneticButtonsForSongs[index].MouseEnter += (s, e) => phoneticButtonsForSongs[index].BackgroundImage = mouseOverImage; - phoneticButtonsForSongs[index].MouseLeave += (s, e) => phoneticButtonsForSongs[index].BackgroundImage = normalImage; + // 設置按鈕的 Tag 屬性為對應的語音符號 + phoneticButtonsForSongs[index].Tag = ButtonsPhoneticSymbols[index]; - // 5. 設定按鈕的點擊事件 (當按下按鈕時,觸發 PhoneticButton_Click) - phoneticButtonsForSongs[index].Click += PhoneticButton_Click; - - // 6. 存入對應的注音符號,方便之後的處理 - phoneticButtonsForSongs[index].Tag = phoneticSymbols[index]; - - // 7. 將按鈕加入視窗 - this.Controls.Add(phoneticButtonsForSongs[index]); + // 將按鈕添加到表單的控制項集合中 + control.Controls.Add(phoneticButtonsForSongs[index]); } catch (Exception ex) { - // 例外處理,確保按鈕建立失敗時不影響其他部分 Console.WriteLine($"Error creating button at index {index}: {ex.Message}"); } } - - /// - /// 初始化注音輸入界面的所有按鈕和輸入框。 - /// - private void InitializeButtonsForZhuYinSongs() - { - // 1. 從設定檔 (config.ini) 載入注音符號 - LoadPhoneticSymbolsFromConfig(); - - // 2. 初始化 35 個注音按鈕 - InitializePhoneticButtonsForSongs(); - - // 3. 初始化特殊按鈕 (例如:刪除、確定、返回按鈕) - InitializeSpecialButtonsForZhuYinSongs(); - - // 4. 初始化輸入框 (用於顯示使用者輸入的注音符號) - InitializeInputBoxZhuYinSongs(); - } - - - /// - /// 初始化注音輸入界面的特殊按鈕,包括「修改」、「清除」和「關閉」。 - /// - private void InitializeSpecialButtonsForZhuYinSongs() - { - // 1. 初始化「修改」按鈕 (刪除上一個輸入的注音符號) - InitializeModifyButtonZhuYinSongs(); - - // 2. 初始化「清除」按鈕 (清空所有輸入內容) - InitializeClearButtonZhuYinSongs(); - - // 3. 初始化「關閉」按鈕 (關閉注音輸入介面) - InitializeCloseButtonZhuYinSongs(); - } - - - /// - /// 初始化「修改」按鈕,讓使用者可以刪除上一個輸入的注音符號。 - /// - private void InitializeModifyButtonZhuYinSongs() - { - // 1. 讀取設定檔 (config.ini) 來獲取特殊按鈕的座標與圖像資訊 - var data = LoadBtnConfigData(); - - // 2. 從設定檔讀取「修改」按鈕的座標數據 - modifyButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "modifyButtonZhuYinSongs"); - - // 3. 從設定檔讀取「修改」按鈕的圖像 (Normal、MouseOver、MouseDown) - var buttonImages = LoadButtonImages(data, "ModifyButtonImagesZhuYin"); - - // 4. 使用座標與圖像來建立「修改」按鈕,並綁定點擊事件 - modifyButtonZhuYinSongs = CreateSpecialButton( - "btnModifyZhuYinSongs", // 按鈕名稱 - modifyButtonZhuYinCoords, // 按鈕座標 - buttonImages.normal, // 預設 (normal) 圖像 - buttonImages.mouseOver, // 滑鼠移過 (hover) 圖像 - buttonImages.mouseDown, // 按下 (pressed) 圖像 - ModifyButtonZhuYinSongs_Click // 綁定按鈕點擊事件 - ); - } - - - /// - /// 「修改」按鈕的點擊事件,刪除輸入框內的最後一個注音符號。 - /// - private void ModifyButtonZhuYinSongs_Click(object sender, EventArgs e) - { - // 1. 確保輸入框 (inputBoxZhuYinSongs) 存在於目前的視窗控制項中 - if (this.Controls.Contains(inputBoxZhuYinSongs) && inputBoxZhuYinSongs.Text.Length > 0) - { - // 2. 刪除輸入框中的最後一個字元 (即移除最後一個注音符號) - inputBoxZhuYinSongs.Text = inputBoxZhuYinSongs.Text.Substring(0, inputBoxZhuYinSongs.Text.Length - 1); - } - } - - /// - /// 初始化「清除」按鈕,並從設定檔載入其位置與圖片資源。 - /// - private void InitializeClearButtonZhuYinSongs() - { - // 1. 從設定檔 (config.ini) 讀取配置數據 - var data = LoadBtnConfigData(); - - // 2. 讀取「清除」按鈕的座標設定 (從 "SpecialButtonCoordinates" 內的 "clearButtonZhuYinSongs" 取得) - clearButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "clearButtonZhuYinSongs"); - - // 3. 讀取「清除」按鈕的圖片 (正常、滑鼠懸停、按下狀態) - var buttonImages = LoadButtonImages(data, "ClearButtonImagesZhuYin"); - - // 4. 建立「清除」按鈕,並設定對應的事件處理函式 (ClearButtonZhuYinSongs_Click) - clearButtonZhuYinSongs = CreateSpecialButton( - "btnClearZhuYinSongs", // 按鈕名稱 - clearButtonZhuYinCoords, // 按鈕座標與大小 - buttonImages.normal, // 正常狀態圖片 - buttonImages.mouseOver, // 滑鼠懸停圖片 - buttonImages.mouseDown, // 按下時圖片 - ClearButtonZhuYinSongs_Click // 點擊事件處理函式 - ); - } - - /// - /// 當使用者點擊「清除」按鈕時,將輸入框 (inputBoxZhuYinSongs) 的內容清空。 - /// - /// 觸發事件的按鈕。 - /// 事件參數。 - private void ClearButtonZhuYinSongs_Click(object sender, EventArgs e) - { - // 1. 確保視窗內包含「注音輸入框」(inputBoxZhuYinSongs),且輸入框內有文字 - if (this.Controls.Contains(inputBoxZhuYinSongs) && inputBoxZhuYinSongs.Text.Length > 0) - { - // 2. 清空輸入框內容 - inputBoxZhuYinSongs.Text = ""; - } - } - - - /// - /// 初始化注音輸入的關閉按鈕,從設定檔讀取按鈕座標與圖片,並設置點擊事件 - /// - private void InitializeCloseButtonZhuYinSongs() - { - // 讀取設定檔數據 - var data = LoadBtnConfigData(); - - // 從設定檔讀取關閉按鈕的座標 - closeButtonZhuYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "closeButtonZhuYinSongs"); - - // 從設定檔讀取關閉按鈕的圖片 - var buttonImages = LoadButtonImages(data, "CloseButtonImagesZhuYin"); - - // 創建關閉按鈕並綁定點擊事件 - closeButtonZhuYinSongs = CreateSpecialButton( - "btnCloseZhuYinSongs", // 按鈕名稱 - closeButtonZhuYinCoords, // 按鈕座標 - buttonImages.normal, // 正常狀態圖片 - buttonImages.mouseOver, // 滑鼠懸停圖片 - buttonImages.mouseDown, // 按下圖片 - CloseButtonZhuYinSongs_Click // 綁定點擊事件 - ); - } - - - /// - /// 關閉注音輸入介面,隱藏相關 UI 元件 - /// - /// 觸發事件的按鈕 (關閉按鈕) - /// 事件參數 - private void CloseButtonZhuYinSongs_Click(object sender, EventArgs e) - { - // 隱藏注音輸入的圖片 - pictureBoxZhuYinSongs.Visible = false; - zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground; - // 隱藏注音輸入的所有按鈕與介面元素 - SetZhuYinSongsAndButtonsVisibility(false); - FindZhuYiSongs(); // 查詢歌曲 - } - /// - /// 查詢歌曲(字數查詢),連接資料庫並執行 SQL 查詢。 - /// - private void FindZhuYiSongs(){ - string searchText = inputBoxZhuYinSongs.Text; - // 在這裡添加搜尋歌曲的邏輯 - // 例如:根據輸入框的內容搜尋歌曲 - - string query = string.IsNullOrWhiteSpace(searchText) - ? "SELECT * FROM song_library_cache ORDER BY `song_id` DESC LIMIT 1000;" - : $"SELECT * FROM song_library_cache WHERE `phonetic_abbr` LIKE '{searchText}%' ORDER BY `song_name`;"; - - var searchResults = SearchSongs_Mysql(query); - // 重置分頁 - currentPage = 0; - totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); - // 更新多頁面面板的內容 - multiPagePanel.currentPageIndex = 0; - multiPagePanel.LoadSongs(searchResults); - } - - - /// - /// 初始化注音輸入框 (RichTextBox),設定外觀、事件處理及位置大小 - /// + // 初始化注音輸入框 (RichTextBox),設定外觀、事件處理及位置大小 private void InitializeInputBoxZhuYinSongs() { try { - // 讀取輸入框的配置,例如字體、顏色、大小等 - LoadInputBoxConfig(); + string fontName = "Times New Roman"; + float fontSize = 26; + FontStyle fontStyle = FontStyle.Regular; + Color foreColor = Color.Black; - // 建立注音輸入框並套用讀取到的設定 inputBoxZhuYinSongs = new RichTextBox { Name = "inputBoxZhuYinSongs", - ForeColor = inputBoxForeColor, // 設定文字顏色 - Font = new Font(inputBoxFontName, inputBoxFontSize, inputBoxFontStyle), // 設定字體 + ForeColor = foreColor, // 設定文字顏色 + Font = new Font(fontName, fontSize / 900 * Screen.PrimaryScreen.Bounds.Height, fontStyle), ScrollBars = RichTextBoxScrollBars.None // 禁用滾動條 }; // 調整輸入框大小與位置 - ResizeAndPositionControl(inputBoxZhuYinSongs, inputBoxZhuYinCoords.X, inputBoxZhuYinCoords.Y, - inputBoxZhuYinCoords.Width, inputBoxZhuYinCoords.Height); + ResizeAndPositionControl(inputBoxZhuYinSongs, 10, 12, 455, 47); // 將輸入框加入到 UI 控制項 - this.Controls.Add(inputBoxZhuYinSongs); + pictureBoxZhuYinSongs.Controls.Add(inputBoxZhuYinSongs); } catch (Exception ex) { Console.WriteLine("Error initializing inputBoxZhuYinSongs: " + ex.Message); } } - - /// - /// 存儲 PictureBoxZhuYinSongs 的座標與尺寸信息。 - /// - /// - /// 此元組包含以下四個值: - /// X:X 座標 - /// , Y:Y 座標 - /// , Width:寬度 - /// , Height:高度 - /// - private (int X, int Y, int Width, int Height) pictureBoxZhuYinSongCoords; - - /// - /// 從設定檔 (config.ini) 讀取 PictureBoxZhuYinSongs 的座標與尺寸 - /// - private void LoadPictureBoxZhuYinSongCoordsFromConfig() - { - // 建立 INI 檔案解析器 - var parser = new FileIniDataParser(); - - // 讀取 config.ini 設定檔的內容 - string iniPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "img.ini"); - IniData data = parser.ReadFile(iniPath); - // 取得 "PictureBoxZhuYinSongs" 段落的設定數據 - var coords = data["PictureBoxZhuYinSongs"]; - - // 解析座標與尺寸,並存入 pictureBoxZhuYinSongCoords - pictureBoxZhuYinSongCoords = ( - int.Parse(coords["X"]), // 讀取 X 座標 - int.Parse(coords["Y"]), // 讀取 Y 座標 - int.Parse(coords["Width"]), // 讀取寬度 - int.Parse(coords["Height"]) // 讀取高度 - ); - } - - - /// - /// 在 pictureBoxZhuYinSongs 上顯示指定路徑的圖片,並根據設定調整其大小與位置。 - /// - /// 要顯示的圖片檔案路徑 + // 在 pictureBoxZhuYinSongs 上顯示指定路徑的圖片,並根據設定調整其大小與位置。 private void ShowImageOnPictureBoxZhuYinSongs(string imagePath) { - // 從 config.ini 讀取 PictureBox 的座標與尺寸 - LoadPictureBoxZhuYinSongCoordsFromConfig(); - // 讀取圖片檔案並載入 Bitmap 物件 Bitmap originalImage = new Bitmap(imagePath); - // 設定圖片顯示區域,使用從設定檔讀取的座標與尺寸 - Rectangle displayArea = new Rectangle( - pictureBoxZhuYinSongCoords.X, - pictureBoxZhuYinSongCoords.Y, - pictureBoxZhuYinSongCoords.Width, - pictureBoxZhuYinSongCoords.Height - ); - // 設定 PictureBox 的圖片 pictureBoxZhuYinSongs.Image = originalImage; // 調整 PictureBox 的大小與位置,使其符合設定 - ResizeAndPositionPictureBox( - pictureBoxZhuYinSongs, - displayArea.X, - displayArea.Y, - displayArea.Width, - displayArea.Height - ); + ResizeAndPositionPictureBox(pictureBoxZhuYinSongs,390, 360, 808, 356); // 顯示 PictureBox pictureBoxZhuYinSongs.Visible = true; } - /// - /// 設定注音歌曲相關的 PictureBox、按鈕和輸入框的可見性。 - /// - /// 若為 true,則顯示這些控件;否則隱藏。 + // 設定注音歌曲相關的 PictureBox、按鈕和輸入框的可見性。 private void SetZhuYinSongsAndButtonsVisibility(bool isVisible) { // 定義要執行的操作,設定各控件的可見性 @@ -439,101 +204,10 @@ namespace DualScreenDemo { // 暫停佈局邏輯,防止在調整控件可見性時觸發不必要的佈局計算,提升性能 SuspendLayout(); - - // 檢查並設定 pictureBoxZhuYinSongs 的可見性 - if (pictureBoxZhuYinSongs == null) - { - Console.WriteLine("pictureBoxZhuYinSongs is null"); - } - else - { - pictureBoxZhuYinSongs.Visible = isVisible; - if (isVisible) pictureBoxZhuYinSongs.BringToFront(); - } - - // 檢查並設定 phoneticButtonsForSongs 陣列中每個按鈕的可見性 - if (phoneticButtonsForSongs == null) - { - Console.WriteLine("phoneticButtonsForSongs is null"); - } - else - { - foreach (var button in phoneticButtonsForSongs) - { - if (button == null) - { - Console.WriteLine("One of the phoneticButtonsForSongs is null"); - } - else - { - button.Visible = isVisible; - if (isVisible) button.BringToFront(); - } - } - } - - // 檢查並設定 modifyButtonZhuYinSongs 的可見性 - if (modifyButtonZhuYinSongs == null) - { - Console.WriteLine("modifyButtonZhuYinSongs is null"); - } - else - { - modifyButtonZhuYinSongs.Visible = isVisible; - if (isVisible) modifyButtonZhuYinSongs.BringToFront(); - } - - // 檢查並設定 clearButtonZhuYinSongs 的可見性 - if (clearButtonZhuYinSongs == null) - { - Console.WriteLine("clearButtonZhuYinSongs is null"); - } - else - { - clearButtonZhuYinSongs.Visible = isVisible; - if (isVisible) clearButtonZhuYinSongs.BringToFront(); - } - - // 檢查並設定 closeButtonZhuYinSongs 的可見性 - if (closeButtonZhuYinSongs == null) - { - Console.WriteLine("closeButtonZhuYinSongs is null"); - } - else - { - closeButtonZhuYinSongs.Visible = isVisible; - if (isVisible) closeButtonZhuYinSongs.BringToFront(); - } - - // 檢查並設定 inputBoxZhuYinSongs 的可見性 - if (inputBoxZhuYinSongs == null) - { - Console.WriteLine("inputBoxZhuYinSongs is null"); - } - else - { - inputBoxZhuYinSongs.Visible = isVisible; - if (isVisible) inputBoxZhuYinSongs.BringToFront(); - } - - // 恢復佈局邏輯,允許佈局計算 + if (isVisible) SetUIVisible(pictureBoxZhuYinSongs); + else CloseUI(pictureBoxZhuYinSongs); ResumeLayout(); - // 強制控件立即執行佈局邏輯,確保佈局更新立即生效 PerformLayout(); - - // 刷新各控件,確保其狀態立即更新 - pictureBoxZhuYinSongs?.Refresh(); - if (phoneticButtonsForSongs != null) - { - foreach (var button in phoneticButtonsForSongs) - { - button?.Refresh(); - } - } - modifyButtonZhuYinSongs?.Refresh(); - clearButtonZhuYinSongs?.Refresh(); - closeButtonZhuYinSongs?.Refresh(); - inputBoxZhuYinSongs?.Refresh(); } catch (Exception ex) { @@ -553,5 +227,77 @@ namespace DualScreenDemo } } + private void ZhuyinSearchSongsButton_Click(object sender, EventArgs e) + { + //更新搜尋模式按鈕的背景圖 + + UpdateSongSearchBtn(zhuyinSearchSongButton, zhuyinSearchSongActiveBackground); + // 讀取 config.ini 並獲取注音圖片的路徑 + var configData = LoadBtnConfigData(); + string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["ZhuYinSongs"]); + //顯示注音歌曲圖片 + ShowImageOnPictureBoxZhuYinSongs(Path.Combine(serverPath, imagePath)); + + + //設定不同模式的UI顯示 + SetWordCountSongsAndButtonsVisibility(false); // 隱藏字數搜尋相關控件 + SetEnglishSongsAndButtonsVisibility(false); + SetPinYinSongsAndButtonsVisibility(false); + SetHandWritingForSongsAndButtonsVisibility(false); + SetSongIDSearchAndButtonsVisibility(false); + SetZhuYinSongsAndButtonsVisibility(true); + ResetinputBox(); + pictureBoxZhuYinSongs.Visible = true; + } + + private void ModifyButtonZhuYinSongs_Click(object sender, EventArgs e) + { + // 1. 確保輸入框 (inputBoxZhuYinSongs) 存在於目前的視窗控制項中 + if (pictureBoxZhuYinSongs.Controls.Contains(inputBoxZhuYinSongs) && inputBoxZhuYinSongs.Text.Length > 0) + { + // 2. 刪除輸入框中的最後一個字元 (即移除最後一個注音符號) + inputBoxZhuYinSongs.Text = inputBoxZhuYinSongs.Text.Substring(0, inputBoxZhuYinSongs.Text.Length - 1); + } + } + + private void ClearButtonZhuYinSongs_Click(object sender, EventArgs e) + { + // 1. 確保視窗內包含「注音輸入框」(inputBoxZhuYinSongs),且輸入框內有文字 + if (pictureBoxZhuYinSongs.Controls.Contains(inputBoxZhuYinSongs) && inputBoxZhuYinSongs.Text.Length > 0) + { + // 2. 清空輸入框內容 + inputBoxZhuYinSongs.Text = ""; + } + } + + private void CloseButtonZhuYinSongs_Click(object sender, EventArgs e) + { + // 隱藏注音輸入的圖片 + pictureBoxZhuYinSongs.Visible = false; + zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground; + // 隱藏注音輸入的所有按鈕與介面元素 + SetZhuYinSongsAndButtonsVisibility(false); + FindZhuYiSongs(); // 查詢歌曲 + } + + private void FindZhuYiSongs() + { + string searchText = inputBoxZhuYinSongs.Text; + // 在這裡添加搜尋歌曲的邏輯 + // 例如:根據輸入框的內容搜尋歌曲 + + string query = string.IsNullOrWhiteSpace(searchText) + ? "SELECT * FROM song_library_cache ORDER BY `song_id` DESC LIMIT 1000;" + : $"SELECT * FROM song_library_cache WHERE `phonetic_abbr` LIKE '{searchText}%' ORDER BY `song_name`;"; + + var searchResults = SearchSongs_Mysql(query); + // 重置分頁 + currentPage = 0; + totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage); + // 更新多頁面面板的內容 + multiPagePanel.currentPageIndex = 0; + multiPagePanel.LoadSongs(searchResults); + } + } } \ No newline at end of file diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 06427fb..488cda5 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -98,13 +98,13 @@ namespace DualScreenDemo.Services private Media addMediaOption(Media media, int audioTrackIndex) { media.AddOption(":avcodec-hw=dxva2"); - media.AddOption(":drop-late-frames"); media.AddOption(":audio-output=directsound"); + media.AddOption(":drop-late-frames"); media.AddOption(":network-caching=300"); media.AddOption(":live-caching=300"); media.AddOption(":file-caching=300"); - media.AddOption(":clock-jitter=0"); - media.AddOption(":clock-synchro=0"); + // media.AddOption(":clock-jitter=0"); + // media.AddOption(":clock-synchro=0"); media.AddOption($":audio-track={audioTrackIndex}"); return media; } diff --git a/img.ini b/img.ini index 9ac58ce..ee00f77 100644 --- a/img.ini +++ b/img.ini @@ -388,73 +388,6 @@ WordCountSongs = themes\superstar\button\4.查詢\4.歌名查詢按鍵\4.歌名 WordCountSingers = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(字數按鍵)_背景.png SongIDSearch = themes\superstar\button\4.查詢\4.歌名查詢按鍵\4.歌名查詢(編號按鍵)_背景.png -[PictureBoxZhuYinSingers] -X = 390 -Y = 354 -Width = 808 -Height = 356 - -[PictureBoxZhuYinSongs] -X = 390 -Y = 350 -Width = 808 -Height = 356 - - - -[PhoneticSymbols] -Symbols=ㄅ,ㄉ,ㄍ,ㄐ,ㄓ,ㄗ,ㄛ,ㄡ,ㄤ,ㄧ,ㄆ,ㄊ,ㄎ,ㄑ,ㄔ,ㄘ,ㄜ,ㄢ,ㄦ,ㄨ,ㄇ,ㄋ,ㄏ,ㄒ,ㄕ,ㄙ,ㄞ,ㄣ,ㄩ,ㄈ,ㄌ, ,ㄖ,ㄚ,ㄠ - -[PhoneticButtonCoordinates] -button0 = 341,418,71,66 -button1 = 406,418,71,66 -button2 = 484,418,71,66 -button3 = 562,418,71,66 -button4 = 640,418,71,66 -button5 = 718,417,71,66 -button6 = 795,418,71,66 -button7 = 873,418,71,66 -button8 = 951,418,71,66 -button9 = 1030,418,71,66 -button10 = 1109,418,71,66 -button11 = 406,489,71,66 -button12 = 484,489,71,66 -button13 = 562,489,71,66 -button14 = 640,489,71,66 -button15 = 718,489,71,66 -button16 = 795,489,71,66 -button17 = 873,489,71,66 -button18 = 951,489,71,66 -button19 = 1030,489,71,66 -button20 = 1109,489,71,66 -button21 = 446,561,71,66 -button22 = 524,561,71,66 -button23 = 602,561,71,66 -button24 = 680,561,71,66 -button25 = 758,561,71,66 -button26 = 836,561,71,66 -button27 = 914,561,71,66 -button28 = 992,561,71,66 -button29 = 1070,561,71,66 -button30 = 484,632,71,66 -button31 = 562,632,71,66 -button32 = 640,632,153,66 -button33 = 800,632,71,66 -button34 = 878,632,71,66 -button35 = 956,632,71,66 - -[SpecialButtonCoordinates] -modifyButtonZhuYinSingers = 1034,632,71,66 -clearButtonZhuYinSingers = 409,632,71,66 -closeButtonZhuYinSingers = 1112,632,71,66 -modifyButtonZhuYinSongs =1035,632,71,66 -clearButtonZhuYinSongs = 408,632,71,66 -closeButtonZhuYinSongs = 1114,632,71,66 - - - - - [ModifyButtonImagesZhuYin] normal = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(拼音按鍵)_←.png @@ -471,16 +404,7 @@ normal = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢( mouseOver = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(注音按鍵)_關閉.png mouseDown = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(注音按鍵)_關閉 複本.png -[InputBoxZhuYinSingers] -X = 408 -Y = 361 -Width = 444 -Height = 47 -FontName = 微軟正黑體 -FontSize = 26 -FontStyle = Regular -ForeColor = Black [PhoneticButtonImages] button0_normal = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(注音按鍵)_ㄅ.png @@ -835,17 +759,6 @@ normal = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢( mouseOver = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(手寫按鍵)_關閉.png mouseDown = themes\superstar\button\4.查詢\3.歌星查詢按鍵\3.歌星查詢(手寫按鍵)_關閉 複本.png -[InputBoxZhuYinSongs] -X=150 -Y=264 -Width=596 -Height=63 -FontName=微軟正黑體 -FontSize=26 -FontStyle=Bold -ForeColor=Black - - [NumberWordCountButtonImages] button0_normal = themes\superstar\button\4.查詢\4.歌名查詢按鍵\4.歌名查詢(字數按鍵)_1.png