2025-04-07 16:54:10 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace DualScreenDemo
|
|
|
|
|
{
|
|
|
|
|
public partial class PrimaryForm
|
|
|
|
|
{
|
|
|
|
|
private PictureBox pictureBoxWordCountSingers;
|
|
|
|
|
private Button modifyButtonWordCountSingers;
|
|
|
|
|
private Button clearButtonWordCountSingers;
|
|
|
|
|
private Button closeButtonWordCountSingers;
|
2025-08-06 10:47:43 +08:00
|
|
|
|
private Button enterButtonWordCountSingers;
|
2025-08-28 17:49:07 +08:00
|
|
|
|
private string[] numberWordCountSymbols=["1","2","3","4","5","6","7","8","9","0"];
|
2025-04-07 16:54:10 +08:00
|
|
|
|
private RichTextBox inputBoxWordCountSingers;
|
|
|
|
|
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 初始化
|
|
|
|
|
private void InitializeButtonsForWordCountSingers()
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 初始化所有語音按鈕
|
|
|
|
|
InitializeNumberWordCountSongsButtons(pictureBoxWordCountSingers, NumberWordCountButton_Click);
|
|
|
|
|
// 初始化注音歌手的輸入框
|
|
|
|
|
InitializeInputBoxWordCountSingers();
|
|
|
|
|
// 初始化下排功能按鈕
|
|
|
|
|
InitializeSingerWordButton();
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
private void InitializeSingerWordButton()
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 加載配置數據
|
|
|
|
|
var data = LoadBtnConfigData();
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 初始化「清除」按鈕
|
|
|
|
|
clearButtonWordCountSingers = new Button { Name = "btnClearWordCountSingers" };
|
|
|
|
|
ConfigureButton(clearButtonWordCountSingers, 55, 274, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesWordCount"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesWordCount"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesWordCount"]["mouseDown"])),
|
|
|
|
|
ClearButtonWordCountSingers_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxWordCountSingers.Controls.Add(clearButtonWordCountSingers);
|
|
|
|
|
|
|
|
|
|
// 初始化「重填」按鈕
|
|
|
|
|
modifyButtonWordCountSingers = new Button { Name = "btnModifyWordCountSingers" };
|
|
|
|
|
ConfigureButton(modifyButtonWordCountSingers, 136, 274, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesWordCount"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesWordCount"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesWordCount"]["mouseDown"])),
|
|
|
|
|
ModifyButtonWordCountSingers_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxWordCountSingers.Controls.Add(modifyButtonWordCountSingers);
|
|
|
|
|
|
|
|
|
|
// 初始化「確認」按鈕
|
|
|
|
|
enterButtonWordCountSingers = new Button { Name = "btnEnterWordCountSingers" };
|
|
|
|
|
ConfigureButton(enterButtonWordCountSingers, 217, 274, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesWordCount"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesWordCount"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["EnterButtonImagesWordCount"]["mouseDown"])),
|
|
|
|
|
(sender, e) => FindWordCountSingers());
|
|
|
|
|
|
|
|
|
|
pictureBoxWordCountSingers.Controls.Add(enterButtonWordCountSingers);
|
|
|
|
|
|
|
|
|
|
// 初始化「關閉」按鈕
|
|
|
|
|
closeButtonWordCountSingers = new Button { Name = "btnCloseWordCountSingers" };
|
|
|
|
|
ConfigureButton(closeButtonWordCountSingers, 298, 274, 72, 67,
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesWordCount"]["normal"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesWordCount"]["mouseOver"])),
|
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesWordCount"]["mouseDown"])),
|
|
|
|
|
CloseButtonWordCountSingers_Click);
|
|
|
|
|
|
|
|
|
|
pictureBoxWordCountSingers.Controls.Add(closeButtonWordCountSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
private void InitializeInputBoxWordCountSingers()
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
try
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 創建一個 RichTextBox 控件來作為輸入框
|
|
|
|
|
inputBoxWordCountSingers = new RichTextBox
|
|
|
|
|
{
|
|
|
|
|
Name = "inputBoxWordCountSingers",
|
|
|
|
|
ForeColor = Color.Black, // 設定文字顏色
|
|
|
|
|
Font = new Font("Times New Roman", 26, FontStyle.Regular), // 設定字體樣式
|
|
|
|
|
ScrollBars = RichTextBoxScrollBars.None // 不顯示滾動條
|
|
|
|
|
};
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 調整和定位輸入框的位置及大小
|
|
|
|
|
ResizeAndPositionControl(inputBoxWordCountSingers, 10, 55, 400, 60);
|
|
|
|
|
// 將輸入框加入到窗體的控件集合中
|
|
|
|
|
pictureBoxWordCountSingers.Controls.Add(inputBoxWordCountSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
|
catch (Exception ex)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 如果初始化過程中出現錯誤,則在控制台輸出錯誤信息
|
|
|
|
|
Console.WriteLine("Error initializing inputBoxWordCountSingers: " + ex.Message);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 顯示圖片並根據配置文件設置顯示區域的大小和位置。
|
|
|
|
|
private void ShowImageOnPictureBoxWordCountSingers(string imagePath)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 加載原始圖片
|
|
|
|
|
Bitmap originalImage = new Bitmap(imagePath);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 設置圖片到 PictureBox
|
|
|
|
|
pictureBoxWordCountSingers.Image = originalImage;
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 調整 PictureBox 大小和位置
|
|
|
|
|
ResizeAndPositionPictureBox(pictureBoxWordCountSingers, 778, 366, 420, 350);
|
|
|
|
|
// 顯示圖片
|
|
|
|
|
pictureBoxWordCountSingers.Visible = true;
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 設置注音歌手相關控制項(包括圖片框、按鈕和輸入框)的顯示或隱藏狀態。
|
|
|
|
|
// <param name="isVisible">指定控件是否可見。True 為顯示,False 為隱藏。</param>
|
|
|
|
|
private void SetWordCountSingersAndButtonsVisibility(bool isVisible)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 定義一個動作來處理控制項的顯示或隱藏
|
|
|
|
|
System.Action action = () =>
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
try
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 暫停控制項佈局的重新排版,提高效率
|
|
|
|
|
SuspendLayout();
|
|
|
|
|
if (isVisible) SetUIVisible(pictureBoxWordCountSingers);
|
|
|
|
|
else CloseUI(pictureBoxWordCountSingers);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Error in SetWordCountSingersAndButtonsVisibility: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 檢查是否需要在主執行緒外執行
|
|
|
|
|
if (this.InvokeRequired)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
this.Invoke(action); // 如果需要,透過主執行緒執行
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
|
else
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
action(); // 否則直接執行
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
#region 按鈕點擊事件
|
|
|
|
|
private void WordCountSearchSingersButton_Click(object sender, EventArgs e)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 設定按鈕背景,將「字數搜尋」設為啟動狀態,其餘按鈕恢復為正常狀態
|
|
|
|
|
UpdateSSearchBtn(wordCountSearchButton, wordCountSearchActiveBackground);
|
|
|
|
|
// 載入設定檔,取得圖片路徑資訊
|
|
|
|
|
var configData = LoadBtnConfigData();
|
|
|
|
|
|
|
|
|
|
// 取得「字數歌手圖片」的完整路徑
|
|
|
|
|
string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["WordCountSingers"]);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 在 PictureBox 中顯示對應的「字數歌手」圖片
|
|
|
|
|
ShowImageOnPictureBoxWordCountSingers(Path.Combine(serverPath, imagePath));
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
// 設定不同搜尋模式的 UI 控件可見性
|
|
|
|
|
SetZhuYinSingersAndButtonsVisibility(false); // 隱藏注音搜尋相關控件
|
|
|
|
|
SetEnglishSingersAndButtonsVisibility(false); // 隱藏英文字母搜尋相關控件
|
|
|
|
|
SetPinYinSingersAndButtonsVisibility(false); // 隱藏拼音搜尋相關控件
|
|
|
|
|
SetHandWritingForSingersAndButtonsVisibility(false); // 隱藏手寫搜尋相關控件
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
|
//SetPictureBoxArtistSearchAndButtonsVisibility(false); // 隱藏其他搜尋模式的圖片框
|
|
|
|
|
SetWordCountSingersAndButtonsVisibility(true); // 顯示字數搜尋相關控件
|
|
|
|
|
ResetinputBox();
|
|
|
|
|
// 顯示「字數歌手搜尋」的圖片框
|
|
|
|
|
pictureBoxWordCountSingers.Visible = true;
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ModifyButtonWordCountSingers_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 如果輸入框不為空,且包含輸入內容,則刪除最後一個字符
|
2025-08-28 17:49:07 +08:00
|
|
|
|
if (pictureBoxWordCountSingers.Controls.Contains(inputBoxWordCountSingers) && inputBoxWordCountSingers.Text.Length > 0)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
|
|
|
|
inputBoxWordCountSingers.Text = inputBoxWordCountSingers.Text.Substring(0, inputBoxWordCountSingers.Text.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearButtonWordCountSingers_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 如果輸入框不為空,則清空該框的文本內容
|
2025-08-28 17:49:07 +08:00
|
|
|
|
if (pictureBoxWordCountSingers.Controls.Contains(inputBoxWordCountSingers) && inputBoxWordCountSingers.Text.Length > 0)
|
2025-04-07 16:54:10 +08:00
|
|
|
|
{
|
|
|
|
|
inputBoxWordCountSingers.Text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseButtonWordCountSingers_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 隱藏 WordCount 歌手圖片框
|
|
|
|
|
pictureBoxWordCountSingers.Visible = false;
|
|
|
|
|
wordCountSearchButton.BackgroundImage = wordCountSearchNormalBackground;
|
|
|
|
|
// 隱藏與 WordCount 歌手相關的所有按鈕
|
|
|
|
|
SetWordCountSingersAndButtonsVisibility(false);
|
|
|
|
|
}
|
2025-08-06 10:47:43 +08:00
|
|
|
|
|
2025-04-14 11:28:41 +08:00
|
|
|
|
private void FindWordCountSingers(){
|
|
|
|
|
string searchText = inputBoxWordCountSingers.Text; // 取得輸入內容
|
|
|
|
|
if (int.TryParse(searchText, out int length))
|
|
|
|
|
{
|
|
|
|
|
//var searchResults = allArtists.Where(artist => artist.Name.Length == length).ToList();
|
2025-05-28 11:04:03 +08:00
|
|
|
|
string query = $"SELECT * FROM artists WHERE CHAR_LENGTH(name) = {length} ;";
|
2025-04-14 11:28:41 +08:00
|
|
|
|
var searchResults = SearchSingers_Mysql(query);
|
|
|
|
|
// 設定當前頁數為 0,並加載搜索結果
|
|
|
|
|
currentPage = 0;
|
|
|
|
|
currentArtistList = searchResults;
|
|
|
|
|
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
|
|
|
|
|
|
|
|
|
|
multiPagePanel.currentPageIndex = 0;
|
|
|
|
|
multiPagePanel.LoadSingers(currentArtistList);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
|
|
private void NumberWordCountButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var button = sender as Button;
|
|
|
|
|
if (button != null && button.Tag != null)
|
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
|
if (inputBoxWordCountSingers.Visible)
|
|
|
|
|
{
|
|
|
|
|
inputBoxWordCountSingers.Text += button.Tag.ToString();
|
|
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
|
}
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
|
#endregion
|
2025-04-07 16:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|