test #1

Merged
jasonchenwork merged 64 commits from test into master 2025-03-18 17:32:23 +08:00
2 changed files with 199 additions and 79 deletions
Showing only changes of commit 193c78fde8 - Show all commits

View File

@ -8,95 +8,138 @@ namespace DualScreenDemo
{
public partial class PrimaryForm
{
/// <summary>
/// 「數字搜尋」按鈕點擊事件
/// 1. 更新所有搜尋按鈕的背景圖片,使「數字搜尋」顯示為啟動狀態
/// 2. 在 `pictureBoxSongIDSearch` 顯示對應的圖片
/// 3. 顯示「數字搜尋」相關 UI 元素
/// </summary>
private void NumberSearchButton2_Click(object sender, EventArgs e)
{
// 更新搜尋按鈕的背景圖片 (將所有按鈕設為未選中狀態,僅數字搜尋為選中狀態)
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
handWritingSearchSongButton.BackgroundImage = handWritingSearchNormalBackground;
numberSearchSongButton.BackgroundImage = numberSearchSongActiveBackground;
numberSearchSongButton.BackgroundImage = numberSearchSongActiveBackground; // 設定數字搜尋為選中狀態
// 在 `pictureBoxSongIDSearch` 顯示數字搜尋的 UI 圖片
ShowImageOnPictureBoxSongIDSearch(Path.Combine(Application.StartupPath, @"themes\superstar\6-1.png"));
// 顯示與數字搜尋相關的 UI 元素
SetPictureBoxSongIDSearchAndButtonsVisibility(true);
pictureBoxSongIDSearch.Visible = true;
}
/// <summary>
/// 在 pictureBoxSongIDSearch 中顯示指定路徑的圖片,並對其進行裁切與調整大小
/// <para> 1. 加載原始圖片 </para>
/// <para> 2. 裁切圖片以符合 UI 需求 </para>
/// <para> 3. 設定 pictureBoxSongIDSearch 的圖片 </para>
/// <para> 4. 調整 pictureBoxSongIDSearch 的位置與大小 </para>
/// <para> 5. 顯示 pictureBoxSongIDSearch </para>
/// </summary>
/// <param name="imagePath">要顯示的圖片路徑</param>
private void ShowImageOnPictureBoxSongIDSearch(string imagePath)
{
// 1. 加載原始圖片
Bitmap originalImage = new Bitmap(imagePath);
// 2. 定義裁切區域 (左上角 x=593, y=135, 寬=507, 高=508)
Rectangle cropArea = new Rectangle(593, 135, 507, 508);
// 3. 進行圖片裁切
Bitmap croppedImage = CropImage(originalImage, cropArea);
// 4. 設定 `pictureBoxSongIDSearch` 的圖片
pictureBoxSongIDSearch.Image = croppedImage;
// 5. 調整 `pictureBoxSongIDSearch` 的大小與位置 (基於 cropArea 並加上偏移量)
ResizeAndPositionPictureBox(pictureBoxSongIDSearch, cropArea.X + offsetXSongID, cropArea.Y + offsetYSongID, cropArea.Width, cropArea.Height);
// 6. 顯示 `pictureBoxSongIDSearch`
pictureBoxSongIDSearch.Visible = true;
}
/// <summary>
/// 當使用者點擊「修改按鈕」時,刪除 `inputBoxSongIDSearch` 輸入框內的最後一個字元。
/// </summary>
/// <param name="sender">觸發事件的對象(按鈕)</param>
/// <param name="e">事件參數</param>
private void ModifyButtonSongIDSearch_Click(object sender, EventArgs e)
{
// 確保 `inputBoxSongIDSearch` 內有文字,避免 `Substring` 發生錯誤
if (inputBoxSongIDSearch.Text.Length > 0)
{
// 刪除輸入框內的最後一個字元
inputBoxSongIDSearch.Text = inputBoxSongIDSearch.Text.Substring(0, inputBoxSongIDSearch.Text.Length - 1);
}
}
/// <summary>
/// 當使用者點擊「關閉按鈕」時,隱藏歌曲編號搜尋的相關 UI 元件。
/// </summary>
/// <param name="sender">觸發事件的對象(按鈕)</param>
/// <param name="e">事件參數</param>
private void CloseButtonSongIDSearch_Click(object sender, EventArgs e)
{
// 隱藏歌曲編號搜尋的相關 UI 元件(包含輸入框、按鈕、圖片等)
SetPictureBoxSongIDSearchAndButtonsVisibility(false);
}
/// <summary>
/// 控制歌曲編號搜尋的 UI 顯示與隱藏。
/// <para>當 <paramref name="isVisible"/> 為 <c>true</c> 時,顯示 UI 元件。</para>
/// <para>當 <paramref name="isVisible"/> 為 <c>false</c> 時,隱藏 UI 元件。</para>
/// </summary>
/// <param name="isVisible">是否顯示 UI</param>
private void SetPictureBoxSongIDSearchAndButtonsVisibility(bool isVisible)
{
// 定義 UI 更新的 Action
System.Action action = () =>
{
// 暫停佈局更新,提高效能
SuspendLayout();
// 控制歌曲編號搜尋圖片的顯示/隱藏
pictureBoxSongIDSearch.Visible = isVisible;
// 如果顯示圖片,則將其置頂
if (isVisible) pictureBoxSongIDSearch.BringToFront();
// 控制「修改」和「關閉」按鈕的可見性
modifyButtonSongIDSearch.Visible = isVisible;
closeButtonSongIDSearch.Visible = isVisible;
// 如果按鈕顯示,則置頂
if (isVisible)
{
modifyButtonSongIDSearch.BringToFront();
closeButtonSongIDSearch.BringToFront();
}
// 控制數字按鈕的可見性
foreach (Button button in numberButtonsSongIDSearch)
{
button.Visible = isVisible;
// 使按鈕顯示時位於最上層
if (isVisible)
button.BringToFront();
}
// 控制輸入框的可見性
inputBoxSongIDSearch.Visible = isVisible;
if (isVisible) inputBoxSongIDSearch.BringToFront();
// 恢復佈局更新
ResumeLayout();
};
// 如果當前執行緒不是 UI 執行緒,則使用 Invoke 呼叫
if (this.InvokeRequired)
{
this.Invoke(action);
@ -106,113 +149,140 @@ namespace DualScreenDemo
action();
}
}
/// <summary>
/// 初始化數字輸入 (Song ID Search) 相關按鈕與輸入框。
/// 這些按鈕用於數字輸入、刪除 (Modify) 及關閉 (Close) 功能。
/// </summary>
private void InitializeButtonsForPictureBoxSongIDSearch()
{
// 數字按鈕的座標陣列 (左上角 X, 左上角 Y, 右下角 X, 右下角 Y)
int[,] coords = new int[,]
{
{651, 292, 752, 400},
{760, 292, 861, 400},
{869, 292, 972, 399},
{652, 401, 752, 502},
{760, 401, 861, 504},
{869, 398, 972, 502},
{651, 502, 753, 607},
{759, 504, 863, 607},
{869, 503, 973, 608},
{981, 501, 1083, 609}
{651, 292, 752, 400}, // 1
{760, 292, 861, 400}, // 2
{869, 292, 972, 399}, // 3
{652, 401, 752, 502}, // 4
{760, 401, 861, 504}, // 5
{869, 398, 972, 502}, // 6
{651, 502, 753, 607}, // 7
{759, 504, 863, 607}, // 8
{869, 503, 973, 608}, // 9
{981, 501, 1083, 609} // 0
};
// 取得螢幕的解析度
int screenW = Screen.PrimaryScreen.Bounds.Width;
int screenH = Screen.PrimaryScreen.Bounds.Height;
// 計算畫面縮放比例
float widthRatio = screenW / (float)1920;
float heightRatio = screenH / (float)900;
// 初始化數字按鈕陣列
numberButtonsSongIDSearch = new Button[10];
// 建立數字按鈕
for (int i = 0; i < numberButtonsSongIDSearch.Length; i++)
{
numberButtonsSongIDSearch[i] = new Button();
// 設定按鈕大小與位置
ConfigureButton(
numberButtonsSongIDSearch[i],
coords[i, 0],
coords[i, 1],
coords[i, 2] - coords[i, 0],
coords[i, 3] - coords[i, 1],
resizedNormalStateImageFor6_1,
resizedMouseOverImageFor6_1,
resizedMouseDownImageFor6_1,
coords[i, 0], // X 座標
coords[i, 1], // Y 座標
coords[i, 2] - coords[i, 0], // 按鈕寬度
coords[i, 3] - coords[i, 1], // 按鈕高度
resizedNormalStateImageFor6_1, // 一般狀態圖片
resizedMouseOverImageFor6_1, // 滑鼠懸停圖片
resizedMouseDownImageFor6_1, // 按下時圖片
null
);
// 重新計算按鈕位置,確保適應不同解析度
int newXForSongID = (int)(((numberButtonsSongIDSearch[i].Location.X / widthRatio) + offsetXSongID) * widthRatio);
int newYForSongID = (int)(((numberButtonsSongIDSearch[i].Location.Y / heightRatio) + offsetYSongID) * heightRatio);
numberButtonsSongIDSearch[i].Location = new Point(newXForSongID, newYForSongID);
// 設定按鈕名稱與 Tag (數字值)
numberButtonsSongIDSearch[i].Name = "NumberButtonSongIDSearch" + i;
numberButtonsSongIDSearch[i].Tag = (i + 1).ToString();
if (i == 9)
if (i == 9) // 最後一個按鈕 (實際上應為數字 "0")
{
numberButtonsSongIDSearch[i].Name = "NumberButtonSongIDSearch0";
numberButtonsSongIDSearch[i].Tag = "0";
}
// 設定按鈕的點擊事件
numberButtonsSongIDSearch[i].Click += SongIDSearchButton_Click;
// 加入畫面
this.Controls.Add(numberButtonsSongIDSearch[i]);
}
modifyButtonSongIDSearch = new Button {
// 初始化「刪除」按鈕 (Modify)
modifyButtonSongIDSearch = new Button
{
Name = "ModifyButtonSongIDSearch",
Tag = "Modify",
Visible = false
};
ConfigureButton(modifyButtonSongIDSearch, 978, 292, 1081 - 978, 397 - 292, resizedNormalStateImageFor6_1, resizedMouseOverImageFor6_1, resizedMouseDownImageFor6_1, ModifyButtonSongIDSearch_Click);
ConfigureButton(modifyButtonSongIDSearch, 978, 292, 1081 - 978, 397 - 292,
resizedNormalStateImageFor6_1, resizedMouseOverImageFor6_1, resizedMouseDownImageFor6_1, ModifyButtonSongIDSearch_Click);
// 調整刪除按鈕位置以適應不同解析度
int newX = (int)(((modifyButtonSongIDSearch.Location.X / widthRatio) + offsetXSongID) * widthRatio);
int newY = (int)(((modifyButtonSongIDSearch.Location.Y / widthRatio) + offsetYSongID) * heightRatio);
int newY = (int)(((modifyButtonSongIDSearch.Location.Y / heightRatio) + offsetYSongID) * heightRatio);
modifyButtonSongIDSearch.Location = new Point(newX, newY);
this.Controls.Add(modifyButtonSongIDSearch);
closeButtonSongIDSearch = new Button {
// 初始化「關閉」按鈕 (Close)
closeButtonSongIDSearch = new Button
{
Name = "CloseButtonSongIDSearch",
Tag = "Close",
Visible = false
};
ConfigureButton(closeButtonSongIDSearch, 982, 147, 1082 - 982, 250 - 147, resizedNormalStateImageFor6_1, resizedMouseOverImageFor6_1, resizedMouseDownImageFor6_1, CloseButtonSongIDSearch_Click);
ConfigureButton(closeButtonSongIDSearch, 982, 147, 1082 - 982, 250 - 147,
resizedNormalStateImageFor6_1, resizedMouseOverImageFor6_1, resizedMouseDownImageFor6_1, CloseButtonSongIDSearch_Click);
// 調整關閉按鈕位置以適應不同解析度
newX = (int)(((closeButtonSongIDSearch.Location.X / widthRatio) + offsetXSongID) * widthRatio);
newY = (int)(((closeButtonSongIDSearch.Location.Y / widthRatio) + offsetYSongID) * heightRatio);
newY = (int)(((closeButtonSongIDSearch.Location.Y / heightRatio) + offsetYSongID) * heightRatio);
closeButtonSongIDSearch.Location = new Point(newX, newY);
this.Controls.Add(closeButtonSongIDSearch);
inputBoxSongIDSearch = new RichTextBox();
inputBoxSongIDSearch.Name = "inputBoxSongIDSearch";
ResizeAndPositionControl(inputBoxSongIDSearch, 645 + offsetXSongID, 197 + offsetXSongID, 986 - 645, 281 - 197);
inputBoxSongIDSearch.ForeColor = Color.Black;
inputBoxSongIDSearch.Font = new Font("細明體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular);
// 初始化輸入框 (RichTextBox)
inputBoxSongIDSearch = new RichTextBox
{
Name = "inputBoxSongIDSearch",
ForeColor = Color.Black,
Font = new Font("細明體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular)
};
// 調整輸入框大小與位置
ResizeAndPositionControl(inputBoxSongIDSearch, 645 + offsetXSongID, 197 + offsetXSongID, 986 - 645, 281 - 197);
// 當輸入框內容改變時,自動搜尋歌曲
inputBoxSongIDSearch.TextChanged += (sender, e) =>
{
string searchText = inputBoxSongIDSearch.Text;
// 使用 LINQ 搜尋符合條件的歌曲 (以輸入的數字開頭)
var searchResults = allSongs.Where(song => song.SongNumber.StartsWith(searchText)).ToList();
// 重設分頁與歌曲列表
currentPage = 0;
currentSongList = searchResults;
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
// 更新歌曲顯示
multiPagePanel.currentPageIndex = 0;
multiPagePanel.LoadSongs(currentSongList);
};
@ -220,16 +290,25 @@ namespace DualScreenDemo
this.Controls.Add(inputBoxSongIDSearch);
}
/// <summary>
/// 數字按鈕點擊事件,將按鈕上的數字 (Tag 值) 加入到 inputBoxSongIDSearch 中。
/// </summary>
/// <param name="sender">觸發事件的按鈕</param>
/// <param name="e">事件參數</param>
private void SongIDSearchButton_Click(object sender, EventArgs e)
{
// 嘗試將 sender 轉型為 Button
var button = sender as Button;
// 確保按鈕不為 null 且具有 Tag 屬性 (Tag 屬性存放數字)
if (button != null && button.Tag != null)
{
// 將按鈕的 Tag 值 (數字) 加入到輸入框
inputBoxSongIDSearch.Text += button.Tag.ToString();
}
}
}
}

View File

@ -4,9 +4,13 @@ using System.Windows.Forms;
namespace DualScreenDemo
{
/* 建構子創立,程式進入初始位置,所有搜尋初始化設置 */
/*
* (PrimaryForm)
* UI
*/
public partial class PrimaryForm
{
// 各種歌曲搜尋按鈕及其對應的背景圖片 (一般狀態 / 啟動狀態)
private Button zhuyinSearchSongButton;
private Bitmap zhuyinSearchSongNormalBackground;
private Bitmap zhuyinSearchSongActiveBackground;
@ -26,8 +30,15 @@ namespace DualScreenDemo
private Bitmap numberSearchSongNormalBackground;
private Bitmap numberSearchSongActiveBackground;
/// <summary>
/// 點擊「歌曲搜尋」按鈕時的事件處理函式
/// 1. 更新導航按鈕的背景圖片,使「歌曲搜尋」按鈕顯示為啟動狀態
/// 2. 隱藏其他搜尋/分類 UI僅顯示歌曲搜尋選單
/// 3. 若有 QR Code 顯示,則將其隱藏
/// </summary>
private void SongSearchButton_Click(object sender, EventArgs e)
{
// 更新導航按鈕的背景圖片
newSongAlertButton.BackgroundImage = newSongAlertNormalBackground;
hotPlayButton.BackgroundImage = hotPlayNormalBackground;
singerSearchButton.BackgroundImage = singerSearchNormalBackground;
@ -41,7 +52,7 @@ namespace DualScreenDemo
deliciousFoodButton.BackgroundImage = deliciousFoodNormalBackground;
isOnOrderedSongsPage = false;
// 隱藏其他 UI
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
SetSingerSearchButtonsVisibility(false);
@ -51,14 +62,15 @@ namespace DualScreenDemo
SetZhuYinSingersAndButtonsVisibility(false);
SetZhuYinSongsAndButtonsVisibility(false);
SetEnglishSingersAndButtonsVisibility(false);
SetPinYinSingersAndButtonsVisibility(false);
SetPinYinSongsAndButtonsVisibility(false);
SetPictureBoxToggleLightAndButtonsVisibility(false);
SetPictureBoxSceneSoundEffectsAndButtonsVisibility(false);
// 顯示歌曲搜尋選單按鈕
SetSongSearchButtonsVisibility(true);
// 隱藏 QR Code (若有)
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = false;
@ -66,12 +78,25 @@ namespace DualScreenDemo
}
}
/// <summary>
/// 設定「歌曲搜尋」相關按鈕的可見性
/// </summary>
/// <param name="isVisible">是否顯示</param>
private void SetSongSearchButtonsVisibility(bool isVisible)
{
pictureBox4.Visible = isVisible;
pictureBox4.Visible = isVisible; // 控制搜尋 UI 背景的可見性
Button[] songSearchButtons = { zhuyinSearchSongButton, englishSearchSongButton, wordCountSearchSongButton, pinyinSearchSongButton, handWritingSearchSongButton, numberSearchSongButton };
// 歌曲搜尋的按鈕陣列
Button[] songSearchButtons = {
zhuyinSearchSongButton,
englishSearchSongButton,
wordCountSearchSongButton,
pinyinSearchSongButton,
handWritingSearchSongButton,
numberSearchSongButton
};
// 設定按鈕可見性,若顯示則移至最前
foreach (var button in songSearchButtons)
{
button.Visible = isVisible;
@ -82,25 +107,41 @@ namespace DualScreenDemo
}
}
/// <summary>
/// 初始化所有「歌曲搜尋」按鈕
/// 依據不同的搜尋方式 (注音、英文、拼音、筆劃、手寫、數字) 建立對應按鈕
/// </summary>
private void InitializeButtonsForSongSearch()
{
InitializeSearchButton(ref zhuyinSearchSongButton, "zhuyinSearchSongButton", 1214, 230, 209, 59, ref zhuyinSearchSongNormalBackground, ref zhuyinSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, ZhuyinSearchSongsButton_Click);
// 初始化「注音搜尋」按鈕
InitializeSearchButton(ref zhuyinSearchSongButton, "zhuyinSearchSongButton",
1214, 230, 209, 59, ref zhuyinSearchSongNormalBackground, ref zhuyinSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, ZhuyinSearchSongsButton_Click);
InitializeSearchButton(ref englishSearchSongButton, "englishSearchSongButton", 1214, 293, 209, 58, ref englishSearchSongNormalBackground, ref englishSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, EnglishSearchSongsButton_Click);
// 初始化「英文搜尋」按鈕
InitializeSearchButton(ref englishSearchSongButton, "englishSearchSongButton",
1214, 293, 209, 58, ref englishSearchSongNormalBackground, ref englishSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, EnglishSearchSongsButton_Click);
InitializeSearchButton(ref pinyinSearchSongButton, "pinyinSearchSongButton", 1214, 356, 209, 58, ref pinyinSearchSongNormalBackground, ref pinyinSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, PinyinSearchSongsButton_Click);
// 初始化「拼音搜尋」按鈕
InitializeSearchButton(ref pinyinSearchSongButton, "pinyinSearchSongButton",
1214, 356, 209, 58, ref pinyinSearchSongNormalBackground, ref pinyinSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, PinyinSearchSongsButton_Click);
InitializeSearchButton(ref wordCountSearchSongButton, "wordCountSearchSongButton", 1214, 418, 209, 59, ref wordCountSearchSongNormalBackground, ref wordCountSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, WordCountSearchSong_Click);
// 初始化「筆劃搜尋」按鈕
InitializeSearchButton(ref wordCountSearchSongButton, "wordCountSearchSongButton",
1214, 418, 209, 59, ref wordCountSearchSongNormalBackground, ref wordCountSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, WordCountSearchSong_Click);
InitializeSearchButton(ref handWritingSearchSongButton, "handWritingSearchSongButton", 1214, 481, 209, 59, ref handWritingSearchSongNormalBackground, ref handWritingSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, HandWritingSearchButtonForSongs_Click);
// 初始化「手寫搜尋」按鈕
InitializeSearchButton(ref handWritingSearchSongButton, "handWritingSearchSongButton",
1214, 481, 209, 59, ref handWritingSearchSongNormalBackground, ref handWritingSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, HandWritingSearchButtonForSongs_Click);
InitializeSearchButton(ref numberSearchSongButton, "numberSearchSongButton", 1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground, normalStateImageSongQuery, mouseDownImageSongQuery, NumberSearchButton2_Click);
// 初始化「數字搜尋」按鈕
InitializeSearchButton(ref numberSearchSongButton, "numberSearchSongButton",
1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground,
normalStateImageSongQuery, mouseDownImageSongQuery, NumberSearchButton2_Click);
}
}
}
}