292 lines
12 KiB
C#
292 lines
12 KiB
C#
using System.IO;
|
|
|
|
namespace DualScreenDemo
|
|
{
|
|
public partial class PrimaryForm
|
|
{
|
|
private PictureBox pictureBoxZhuYinSingers;
|
|
private Button[] phoneticButtonsForSingers;
|
|
private Button modifyButtonZhuYinSingers;
|
|
private Button clearButtonZhuYinSingers;
|
|
private Button closeButtonZhuYinSingers;
|
|
private RichTextBox inputBoxZhuYinSingers;
|
|
|
|
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(); // 否則直接執行
|
|
}
|
|
}
|
|
|
|
private void ZhuyinSearchSingersButton_Click(object sender, EventArgs e)
|
|
{
|
|
// 設定按鈕背景,將「注音搜尋」設為啟動狀態,其餘按鈕恢復為正常狀態
|
|
|
|
UpdateSSearchBtn(zhuyinSearchButton, zhuyinSearchActiveBackground);
|
|
// 載入設定檔,取得圖片路徑資訊
|
|
var configData = LoadBtnConfigData();
|
|
|
|
// 取得「注音歌手圖片」的完整路徑
|
|
string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["ZhuYinSingers"]);
|
|
|
|
// 在 PictureBox 中顯示對應的「注音歌手」圖片
|
|
ShowImageOnPictureBoxZhuYinSingers(Path.Combine(serverPath, imagePath));
|
|
|
|
// 設定不同搜尋模式的 UI 控件可見性
|
|
SetEnglishSingersAndButtonsVisibility(false); // 隱藏英文字母搜尋相關控件
|
|
SetPinYinSingersAndButtonsVisibility(false); // 隱藏拼音搜尋相關控件
|
|
SetHandWritingForSingersAndButtonsVisibility(false); // 隱藏手寫搜尋相關控件
|
|
SetWordCountSingersAndButtonsVisibility(false); // 隱藏字數搜尋相關控件
|
|
|
|
SetZhuYinSingersAndButtonsVisibility(true); // 顯示注音搜尋相關控件
|
|
//SetPictureBoxArtistSearchAndButtonsVisibility(false); // 隱藏其他搜尋模式的圖片框
|
|
|
|
ResetinputBox(); // 重置輸入框
|
|
|
|
// 顯示「注音歌手搜尋」的圖片框
|
|
pictureBoxZhuYinSingers.Visible = true;
|
|
}
|
|
private void ModifyButtonZhuYinSingers_Click(object sender, EventArgs e)
|
|
{
|
|
// 如果輸入框不為空,且包含輸入內容,則刪除最後一個字符
|
|
if (pictureBoxZhuYinSingers.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0)
|
|
{
|
|
inputBoxZhuYinSingers.Text = inputBoxZhuYinSingers.Text.Substring(0, inputBoxZhuYinSingers.Text.Length - 1);
|
|
}
|
|
}
|
|
private void ClearButtonZhuYinSingers_Click(object sender, EventArgs e)
|
|
{
|
|
// 如果輸入框不為空,則清空該框的文本內容
|
|
if (pictureBoxZhuYinSingers.Controls.Contains(inputBoxZhuYinSingers) && inputBoxZhuYinSingers.Text.Length > 0)
|
|
{
|
|
inputBoxZhuYinSingers.Text = "";
|
|
}
|
|
}
|
|
private void CloseButtonZhuYinSingers_Click(object sender, EventArgs e)
|
|
{
|
|
// 隱藏 ZhuYin 歌手圖片框
|
|
pictureBoxZhuYinSingers.Visible = false;
|
|
// 關閉注音搜尋的按鈕顏色
|
|
zhuyinSearchButton.BackgroundImage = zhuyinSearchNormalBackground;
|
|
FindZhuYiSingers();
|
|
// 隱藏與 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);
|
|
}
|
|
|
|
}
|
|
} |