2025-04-07 16:54:10 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace DualScreenDemo
|
|
|
|
|
{
|
|
|
|
|
public partial class PrimaryForm
|
|
|
|
|
{
|
|
|
|
|
// 拼音歌曲的 PictureBox
|
|
|
|
|
private PictureBox pictureBoxPinYinSongs;
|
|
|
|
|
// 存放拼音按鈕的陣列
|
|
|
|
|
private Button[] letterButtonsForPinYinSongs;
|
2025-08-29 16:15:54 +08:00
|
|
|
|
private string[] AlphabetSymbols=["Q","W","E","R","T","Y","U","I","O","P",
|
|
|
|
|
"A","S","D","F","G","H","J","K","L",
|
|
|
|
|
"Z","X","C","V","B","N","M"];
|
2025-04-07 16:54:10 +08:00
|
|
|
|
// 特殊功能按鈕(修改、清除、關閉)
|
|
|
|
|
private Button modifyButtonPinYinSongs;
|
|
|
|
|
private Button clearButtonPinYinSongs;
|
|
|
|
|
private Button closeButtonPinYinSongs;
|
|
|
|
|
// 用於顯示輸入文字的輸入框
|
|
|
|
|
private RichTextBox inputBoxPinYinSongs;
|
2025-08-29 16:15:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化拼音輸入相關的 UI 控件
|
|
|
|
|
private void InitializeButtonsForPinYinSongs()
|
|
|
|
|
{
|
|
|
|
|
InitializeInputBoxPinYinSongs();
|
|
|
|
|
InitializePinYinSongsButton();
|
|
|
|
|
InitializeAlphbtBtns(pictureBoxPinYinSongs,LetterButtonPinYinSongs_Click);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化拼音輸入框 (RichTextBox)
|
|
|
|
|
private void InitializeInputBoxPinYinSongs()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//字型設定
|
|
|
|
|
string fontName = "Times New Roman";
|
|
|
|
|
float fontSize = 26;
|
|
|
|
|
FontStyle fontStyle = FontStyle.Regular;
|
|
|
|
|
Color foreColor = Color.Black;
|
|
|
|
|
|
|
|
|
|
// 創建拼音輸入框 (RichTextBox)
|
|
|
|
|
inputBoxPinYinSongs = new RichTextBox
|
|
|
|
|
{
|
|
|
|
|
Visible = false, // 預設為隱藏
|
|
|
|
|
Name = "inputBoxPinYinSongs", // 設定控制項名稱
|
|
|
|
|
ForeColor = foreColor, // 設定文字顏色
|
|
|
|
|
Font = new Font(
|
|
|
|
|
fontName,
|
|
|
|
|
fontSize / 900 * Screen.PrimaryScreen.Bounds.Height, // 根據螢幕大小調整字體
|
|
|
|
|
fontStyle
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 設定輸入框的位置與大小
|
|
|
|
|
ResizeAndPositionControl(inputBoxPinYinSongs, 20,25, 448, 57);
|
|
|
|
|
|
|
|
|
|
pictureBoxPinYinSongs.Controls.Add(inputBoxPinYinSongs);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"An error occurred: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void InitializePinYinSongsButton()
|
|
|
|
|
{
|
|
|
|
|
var data = LoadBtnConfigData();
|
|
|
|
|
|
|
|
|
|
modifyButtonPinYinSongs = new Button { Name = "modifyButtonPinYinSongs" };
|
|
|
|
|
ConfigureButton(modifyButtonPinYinSongs, 650, 264, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesPinYin"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesPinYin"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesPinYin"]["mouseDown"])),
|
|
|
|
|
ModifyButtonPinYinSongs_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxPinYinSongs.Controls.Add(modifyButtonPinYinSongs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clearButtonPinYinSongs = new Button { Name = "clearButtonPinYinSongs" };
|
|
|
|
|
ConfigureButton(clearButtonPinYinSongs, 8, 264, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesPinYin"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesPinYin"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesPinYin"]["mouseDown"])),
|
|
|
|
|
ClearButtonPinYinSongs_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxPinYinSongs.Controls.Add(clearButtonPinYinSongs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closeButtonPinYinSongs = new Button { Name = "closeButtonPinYinSongs" };
|
|
|
|
|
ConfigureButton(closeButtonPinYinSongs, 730, 264, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesPinYin"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesPinYin"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesPinYin"]["mouseDown"])),
|
|
|
|
|
CloseButtonPinYinSongs_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxPinYinSongs.Controls.Add(closeButtonPinYinSongs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeAlphbtBtns(Control control, EventHandler handler)
|
|
|
|
|
{
|
|
|
|
|
// 初始化字母按鈕陣列,總共有 26 個按鈕
|
|
|
|
|
letterButtonsForPinYinSongs = new Button[26];
|
|
|
|
|
|
|
|
|
|
// 設置上排按鈕
|
|
|
|
|
int x = 8;
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
CreateAlphbtBtns(i, x, 100, control, handler);
|
|
|
|
|
x += 80;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x = 40;
|
|
|
|
|
for (int i = 10; i < 19; i++)
|
|
|
|
|
{
|
|
|
|
|
CreateAlphbtBtns(i, x, 182, control, handler);
|
|
|
|
|
x += 80;
|
|
|
|
|
}
|
|
|
|
|
// 設置下排按鈕
|
|
|
|
|
x = 88;
|
|
|
|
|
for (int i = 19; i < 26; i++)
|
|
|
|
|
{
|
|
|
|
|
CreateAlphbtBtns(i, x, 264, control, handler);
|
|
|
|
|
x += 80;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void CreateAlphbtBtns(int index, int x, int y,Control control,EventHandler handler)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 加載配置數據
|
|
|
|
|
var data = LoadBtnConfigData();
|
|
|
|
|
// 創建語音按鈕並設置其屬性
|
|
|
|
|
letterButtonsForPinYinSongs[index] = new Button
|
|
|
|
|
{
|
|
|
|
|
Name = $"PinYinLetterButtons_{AlphabetSymbols[index]}", // 按鈕名稱設為語音符號名稱
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ConfigureButton(letterButtonsForPinYinSongs[index], x, y, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["PinYinLetterButtonImages"][$"button{index}_normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["PinYinLetterButtonImages"][$"button{index}_mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["PinYinLetterButtonImages"][$"button{index}_mouseDown"])),
|
|
|
|
|
handler);
|
|
|
|
|
|
|
|
|
|
// 設置按鈕的 Tag 屬性為對應的語音符號
|
|
|
|
|
letterButtonsForPinYinSongs[index].Tag = AlphabetSymbols[index];
|
|
|
|
|
|
|
|
|
|
// 將按鈕添加到表單的控制項集合中
|
|
|
|
|
control.Controls.Add(letterButtonsForPinYinSongs[index]);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Error creating button at index {index}: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 顯示拼音歌曲圖片
|
|
|
|
|
// <param name="imagePath">圖片路徑</param>
|
|
|
|
|
private void ShowImageOnPictureBoxPinYinSongs(string imagePath)
|
|
|
|
|
{
|
|
|
|
|
// 使用指定的圖片路徑建立 Bitmap 影像
|
|
|
|
|
Bitmap originalImage = new Bitmap(imagePath);
|
|
|
|
|
|
|
|
|
|
// 將載入的圖片設定為 pictureBoxPinYinSongs 的影像
|
|
|
|
|
pictureBoxPinYinSongs.Image = originalImage;
|
|
|
|
|
|
|
|
|
|
// 調整 PictureBox 的大小與位置
|
|
|
|
|
ResizeAndPositionPictureBox(pictureBoxPinYinSongs, 390, 360, 808, 356);
|
|
|
|
|
// 顯示 PictureBox
|
|
|
|
|
pictureBoxPinYinSongs.Visible = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 設定拼音模式的 UI 是否可見
|
|
|
|
|
// <param name="isVisible">是否可見</param>
|
|
|
|
|
private void SetPinYinSongsAndButtonsVisibility(bool isVisible)
|
|
|
|
|
{
|
|
|
|
|
// 定義一個委派 (Action),用於更新 UI 控件的可見性
|
|
|
|
|
System.Action action = () =>
|
|
|
|
|
{
|
|
|
|
|
SuspendLayout();
|
|
|
|
|
if (isVisible) SetUIVisible(pictureBoxPinYinSongs);
|
|
|
|
|
else CloseUI(pictureBoxPinYinSongs);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 如果當前執行緒不是 UI 執行緒,則使用 Invoke 確保執行於 UI 執行緒
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(action);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
action();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 按鈕點擊事件
|
|
|
|
|
// 拼音歌曲搜尋按鈕點擊事件
|
2025-04-07 16:54:10 +08:00
|
|
|
|
private void PinyinSearchSongsButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 更新搜尋模式按鈕的背景圖
|
|
|
|
|
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
|
|
|
|
|
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
|
|
|
|
|
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongActiveBackground;
|
|
|
|
|
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
|
|
|
|
|
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
|
|
|
|
|
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
|
|
|
|
|
|
|
|
|
|
// 讀取 config.ini 並獲取拼音圖片的路徑
|
2025-08-13 14:07:32 +08:00
|
|
|
|
var configData = LoadBtnConfigData();
|
2025-08-07 13:09:10 +08:00
|
|
|
|
string pinyinImagePath = Path.Combine(serverPath, configData["ImagePaths"]["PinYinSongs"]);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
// 顯示拼音歌曲圖片
|
2025-08-07 13:09:10 +08:00
|
|
|
|
ShowImageOnPictureBoxPinYinSongs(Path.Combine(serverPath, pinyinImagePath));
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 鍵盤UI介面顯示設定
|
|
|
|
|
SetWordCountSongsAndButtonsVisibility(false);
|
|
|
|
|
SetEnglishSongsAndButtonsVisibility(false);
|
|
|
|
|
SetPinYinSongsAndButtonsVisibility(true);
|
|
|
|
|
SetHandWritingForSongsAndButtonsVisibility(false);
|
|
|
|
|
SetSongIDSearchAndButtonsVisibility(false);
|
|
|
|
|
SetZhuYinSongsAndButtonsVisibility(false);
|
|
|
|
|
|
|
|
|
|
ResetinputBox();
|
|
|
|
|
pictureBoxPinYinSongs.Visible = true;
|
2025-08-29 16:15:54 +08:00
|
|
|
|
}
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-29 16:15:54 +08:00
|
|
|
|
// 處理拼音按鈕點擊事件
|
2025-04-07 16:54:10 +08:00
|
|
|
|
private void LetterButtonPinYinSongs_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 嘗試將觸發事件的物件轉換為 Button 類型
|
|
|
|
|
var button = sender as Button;
|
|
|
|
|
|
|
|
|
|
// 檢查按鈕是否為 null,並確保該按鈕的 Tag 屬性不為 null
|
|
|
|
|
if (button != null && button.Tag != null)
|
|
|
|
|
{
|
|
|
|
|
// 確保輸入框 (inputBoxPinYinSongs) 是可見狀態
|
|
|
|
|
if (inputBoxPinYinSongs.Visible)
|
|
|
|
|
{
|
|
|
|
|
// 將按鈕的標籤 (Tag) 轉換為字串,並附加到輸入框的文字內容中
|
|
|
|
|
inputBoxPinYinSongs.Text += button.Tag.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-29 16:15:54 +08:00
|
|
|
|
// 「修改」按鈕點擊事件:刪除拼音輸入框中的最後一個字母。
|
2025-04-07 16:54:10 +08:00
|
|
|
|
private void ModifyButtonPinYinSongs_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 確保 inputBoxPinYinSongs 存在於視窗控制項集合內,且輸入框內有文字
|
2025-08-29 16:15:54 +08:00
|
|
|
|
if (pictureBoxPinYinSongs.Controls.Contains(inputBoxPinYinSongs) && inputBoxPinYinSongs.Text.Length > 0)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
|
|
|
|
// 刪除輸入框內的最後一個字母
|
|
|
|
|
inputBoxPinYinSongs.Text = inputBoxPinYinSongs.Text.Substring(0, inputBoxPinYinSongs.Text.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-29 16:15:54 +08:00
|
|
|
|
// 當使用者點擊清除按鈕時,若輸入框存在且有內容,則將其清空。
|
2025-04-07 16:54:10 +08:00
|
|
|
|
private void ClearButtonPinYinSongs_Click(object sender, EventArgs e)
|
2025-08-29 16:15:54 +08:00
|
|
|
|
{
|
2025-04-07 16:54:10 +08:00
|
|
|
|
// 檢查視窗內是否包含 inputBoxPinYinSongs 控制項,且輸入框內是否有文字
|
2025-08-29 16:15:54 +08:00
|
|
|
|
if (pictureBoxPinYinSongs.Controls.Contains(inputBoxPinYinSongs) && inputBoxPinYinSongs.Text.Length > 0)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
|
|
|
|
// 清空拼音輸入框的內容
|
|
|
|
|
inputBoxPinYinSongs.Text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void CloseButtonPinYinSongs_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 隱藏拼音輸入的背景圖片 (可能是 UI 中的輸入框背景)
|
|
|
|
|
pictureBoxPinYinSongs.Visible = false;
|
|
|
|
|
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
|
|
|
|
|
// 設定拼音輸入框與所有相關按鈕的可見性為 false
|
|
|
|
|
SetPinYinSongsAndButtonsVisibility(false);
|
2025-04-11 11:08:13 +08:00
|
|
|
|
FindPinYinSongs();
|
|
|
|
|
}
|
|
|
|
|
private void FindPinYinSongs(){
|
|
|
|
|
string searchText = inputBoxPinYinSongs.Text;
|
|
|
|
|
// 在這裡添加搜尋歌曲的邏輯
|
|
|
|
|
// 例如:根據輸入框的內容搜尋歌曲
|
2025-04-15 10:59:03 +08:00
|
|
|
|
string query = string.IsNullOrWhiteSpace(searchText)
|
2025-08-06 10:47:43 +08:00
|
|
|
|
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 1000;"
|
2025-08-08 11:11:15 +08:00
|
|
|
|
: $"SELECT * FROM song_library_cache WHERE pinyin_abbr LIKE '{searchText}%' ORDER BY `song_name` DESC;";
|
2025-04-11 11:08:13 +08:00
|
|
|
|
var searchResults = SearchSongs_Mysql(query);
|
|
|
|
|
// 重置分頁
|
|
|
|
|
currentPage = 0;
|
|
|
|
|
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
|
|
|
|
|
// 更新多頁面面板的內容
|
|
|
|
|
multiPagePanel.currentPageIndex = 0;
|
2025-07-14 18:08:12 +08:00
|
|
|
|
multiPagePanel.LoadSongs(searchResults);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
2025-08-29 16:15:54 +08:00
|
|
|
|
#endregion
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|