test #1
@ -45,7 +45,9 @@ namespace DualScreenDemo
|
||||
SetPinYinSongsAndButtonsVisibility(true);
|
||||
pictureBoxPinYinSongs.Visible = true;
|
||||
}
|
||||
// 初始化拼音按鈕
|
||||
/// <summary>
|
||||
/// 初始化拼音按鈕
|
||||
/// </summary>
|
||||
private void InitializeLetterButtonsForPinYinSongs()
|
||||
{
|
||||
// 從設定檔 (config.ini) 讀取配置數據
|
||||
@ -83,7 +85,11 @@ namespace DualScreenDemo
|
||||
this.Controls.Add(letterButtonsForPinYinSongs[i]);
|
||||
}
|
||||
}
|
||||
// 處理拼音按鈕點擊事件
|
||||
/// <summary>
|
||||
/// 處理拼音按鈕點擊事件
|
||||
/// </summary>
|
||||
/// <param name="sender">觸發事件按鈕</param>
|
||||
/// <param name="e">事件參數</param>
|
||||
private void LetterButtonPinYinSongs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 嘗試將觸發事件的物件轉換為 Button 類型
|
||||
@ -101,43 +107,55 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化拼音輸入相關的 UI 控件,包括字母按鈕、特殊功能按鈕(修改、清除、關閉),以及拼音輸入框。
|
||||
/// </summary>
|
||||
private void InitializeButtonsForPinYinSongs()
|
||||
{
|
||||
// 初始化拼音字母按鈕,根據 QWERTY 鍵盤佈局建立對應的按鈕
|
||||
InitializeLetterButtonsForPinYinSongs();
|
||||
|
||||
// 初始化特殊功能按鈕,包括修改、清除和關閉按鈕
|
||||
// 初始化特殊功能按鈕(修改、清除、關閉)
|
||||
InitializeSpecialButtonsForPinYinSongs();
|
||||
|
||||
// 初始化拼音輸入框,讓使用者可以輸入拼音來搜尋歌曲
|
||||
// 初始化拼音輸入框,使用者可透過輸入拼音來搜尋歌曲
|
||||
InitializeInputBoxPinYinSongs();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化拼音輸入的特殊功能按鈕,包括:
|
||||
/// 1. 修改按鈕 - 刪除輸入框中的最後一個字母
|
||||
/// 2. 清除按鈕 - 清空輸入框的內容
|
||||
/// 3. 關閉按鈕 - 隱藏拼音輸入的 UI 元件
|
||||
/// </summary>
|
||||
private void InitializeSpecialButtonsForPinYinSongs()
|
||||
{
|
||||
|
||||
// 初始化「修改」按鈕,讓使用者可以刪除輸入框中的最後一個字母
|
||||
// 初始化「修改」按鈕(刪除輸入框最後一個字母)
|
||||
InitializeModifyButtonPinYinSongs();
|
||||
|
||||
// 初始化「清除」按鈕,讓使用者可以清空輸入框的內容
|
||||
// 初始化「清除」按鈕(清空輸入框內容)
|
||||
InitializeClearButtonPinYinSongs();
|
||||
|
||||
// 初始化「關閉」按鈕,讓使用者可以關閉拼音輸入的 UI 元件
|
||||
// 初始化「關閉」按鈕(關閉拼音輸入 UI)
|
||||
InitializeCloseButtonPinYinSongs();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化「修改」按鈕,提供刪除拼音輸入框最後一個字母的功能。
|
||||
/// </summary>
|
||||
private void InitializeModifyButtonPinYinSongs()
|
||||
{
|
||||
// 載入設定檔資料,取得特殊按鈕的相關配置
|
||||
// 讀取設定檔,載入特殊按鈕的配置資料
|
||||
var data = LoadConfigData();
|
||||
|
||||
// 從設定檔讀取「修改按鈕」的座標位置與大小
|
||||
// 從設定檔取得「修改按鈕」的座標與大小
|
||||
modifyButtonPinYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "modifyButtonPinYinSongs");
|
||||
|
||||
// 從設定檔讀取「修改按鈕」的不同狀態圖片 (一般、滑鼠懸停、按下)
|
||||
// 讀取「修改按鈕」的圖片資源(一般狀態、滑鼠懸停、按下)
|
||||
var buttonImages = LoadButtonImages(data, "ModifyButtonImagesPinYin");
|
||||
|
||||
// 創建「修改按鈕」,並綁定點擊事件
|
||||
// 創建「修改」按鈕,並綁定點擊事件
|
||||
modifyButtonPinYinSongs = CreateSpecialButton(
|
||||
"btnModifyPinYinSongs", // 按鈕名稱
|
||||
modifyButtonPinYinCoords, // 設定按鈕的座標與大小
|
||||
@ -146,43 +164,51 @@ namespace DualScreenDemo
|
||||
buttonImages.mouseDown, // 設定按鈕的按下狀態圖片
|
||||
ModifyButtonPinYinSongs_Click // 綁定按鈕的點擊事件處理函式
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 「修改」按鈕點擊事件:刪除拼音輸入框 (`inputBoxPinYinSongs`) 中的最後一個字母。
|
||||
/// </summary>
|
||||
private void ModifyButtonPinYinSongs_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
// 檢查 `inputBoxPinYinSongs` 是否已被加入到 `Controls` 集合中 (確保輸入框存在)
|
||||
// 確保 `inputBoxPinYinSongs` 存在於視窗控制項集合內,且輸入框內有文字
|
||||
if (this.Controls.Contains(inputBoxPinYinSongs) && inputBoxPinYinSongs.Text.Length > 0)
|
||||
{
|
||||
// 若 `inputBoxPinYinSongs` 有內容,刪除最後一個字母
|
||||
// 刪除輸入框內的最後一個字母
|
||||
inputBoxPinYinSongs.Text = inputBoxPinYinSongs.Text.Substring(0, inputBoxPinYinSongs.Text.Length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化「清除」按鈕 (`clearButtonPinYinSongs`),用於清空拼音輸入框 (`inputBoxPinYinSongs`)。
|
||||
/// </summary>
|
||||
private void InitializeClearButtonPinYinSongs()
|
||||
{
|
||||
// 從設定檔載入資料
|
||||
var data = LoadConfigData();
|
||||
|
||||
// 讀取清除按鈕的座標配置 (X, Y, Width, Height)
|
||||
// 讀取「清除」按鈕的座標配置 (X, Y, Width, Height)
|
||||
clearButtonPinYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "clearButtonPinYinSongs");
|
||||
|
||||
// 載入清除按鈕的圖片 (一般狀態、滑鼠懸停、按下時的圖片)
|
||||
// 載入「清除」按鈕的圖片 (一般狀態、滑鼠懸停、按下時的圖片)
|
||||
var buttonImages = LoadButtonImages(data, "ClearButtonImagesPinYin");
|
||||
|
||||
// 建立「清除按鈕」並指定對應的座標與圖片
|
||||
// 建立「清除」按鈕,設定對應的座標與圖片,並綁定點擊事件
|
||||
clearButtonPinYinSongs = CreateSpecialButton(
|
||||
"btnClearPinYinSongs", // 按鈕名稱
|
||||
clearButtonPinYinCoords, // 按鈕的座標與大小
|
||||
buttonImages.normal, // 按鈕的普通狀態圖片
|
||||
buttonImages.mouseOver, // 滑鼠懸停時的圖片
|
||||
buttonImages.mouseDown, // 滑鼠按下時的圖片
|
||||
ClearButtonPinYinSongs_Click // 點擊事件處理函式
|
||||
clearButtonPinYinCoords, // 設定按鈕的座標與大小
|
||||
buttonImages.normal, // 設定按鈕的正常狀態圖片
|
||||
buttonImages.mouseOver, // 設定按鈕的滑鼠懸停圖片
|
||||
buttonImages.mouseDown, // 設定按鈕的按下狀態圖片
|
||||
ClearButtonPinYinSongs_Click // 綁定按鈕的點擊事件處理函式
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空拼音輸入框的內容。
|
||||
/// 當使用者點擊清除按鈕時,若輸入框存在且有內容,則將其清空。
|
||||
/// </summary>
|
||||
private void ClearButtonPinYinSongs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 檢查視窗內是否包含 inputBoxPinYinSongs 控制項,且輸入框內是否有文字
|
||||
@ -193,29 +219,36 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化「關閉」按鈕 (`closeButtonPinYinSongs`),用於隱藏拼音輸入介面。
|
||||
/// </summary>
|
||||
private void InitializeCloseButtonPinYinSongs()
|
||||
{
|
||||
// 讀取設定檔中的按鈕配置數據
|
||||
var data = LoadConfigData();
|
||||
|
||||
// 從設定檔中取得「關閉」按鈕的座標
|
||||
// 從設定檔中取得「關閉」按鈕的座標 (X, Y, Width, Height)
|
||||
closeButtonPinYinCoords = LoadSpecialButtonCoordinates(data, "SpecialButtonCoordinates", "closeButtonPinYinSongs");
|
||||
|
||||
// 從設定檔中讀取「關閉」按鈕的圖片
|
||||
// 從設定檔中讀取「關閉」按鈕的圖片 (一般狀態、滑鼠懸停、按下時的圖片)
|
||||
var buttonImages = LoadButtonImages(data, "CloseButtonImagesPinYin");
|
||||
|
||||
// 建立「關閉」按鈕,並設定名稱、座標、按鈕圖片及點擊事件
|
||||
// 建立「關閉」按鈕,設定名稱、座標、圖片及點擊事件
|
||||
closeButtonPinYinSongs = CreateSpecialButton(
|
||||
"btnClosePinYinSongs", // 按鈕名稱
|
||||
closeButtonPinYinCoords, // 按鈕座標 (X, Y, Width, Height)
|
||||
buttonImages.normal, // 按鈕的普通狀態圖片
|
||||
buttonImages.mouseOver, // 滑鼠懸停時的圖片
|
||||
buttonImages.mouseDown, // 按下時的圖片
|
||||
CloseButtonPinYinSongs_Click // 點擊事件處理函式
|
||||
"btnClosePinYinSongs", // 按鈕名稱
|
||||
closeButtonPinYinCoords, // 設定按鈕的座標與大小
|
||||
buttonImages.normal, // 設定按鈕的正常狀態圖片
|
||||
buttonImages.mouseOver, // 設定按鈕的滑鼠懸停圖片
|
||||
buttonImages.mouseDown, // 設定按鈕的按下狀態圖片
|
||||
CloseButtonPinYinSongs_Click // 綁定按鈕的點擊事件處理函式
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 關閉拼音輸入模式,隱藏相關 UI 元件。
|
||||
/// </summary>
|
||||
/// <param name="sender">觸發事件的按鈕。</param>
|
||||
/// <param name="e">事件參數。</param>
|
||||
private void CloseButtonPinYinSongs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 隱藏拼音輸入的背景圖片 (可能是 UI 中的輸入框背景)
|
||||
@ -224,7 +257,9 @@ namespace DualScreenDemo
|
||||
SetPinYinSongsAndButtonsVisibility(false);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化拼音輸入框 (`RichTextBox`),並從 `config.ini` 讀取相關設定。
|
||||
/// </summary>
|
||||
private void InitializeInputBoxPinYinSongs()
|
||||
{
|
||||
try
|
||||
@ -245,13 +280,13 @@ namespace DualScreenDemo
|
||||
data = parser.ReadData(reader);
|
||||
}
|
||||
|
||||
// 從 INI 檔案讀取拼音輸入框的位置與大小
|
||||
// **從 INI 檔案讀取拼音輸入框的位置與大小**
|
||||
int x = int.Parse(data["InputBoxPinYinSongs"]["X"]); // X 座標
|
||||
int y = int.Parse(data["InputBoxPinYinSongs"]["Y"]); // Y 座標
|
||||
int width = int.Parse(data["InputBoxPinYinSongs"]["Width"]); // 寬度
|
||||
int height = int.Parse(data["InputBoxPinYinSongs"]["Height"]); // 高度
|
||||
|
||||
// 讀取字型設定
|
||||
// **讀取字型設定**
|
||||
string fontName = data["InputBoxPinYinSongs"]["FontName"]; // 字型名稱
|
||||
float fontSize = float.Parse(data["InputBoxPinYinSongs"]["FontSize"]); // 字體大小
|
||||
FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), data["InputBoxPinYinSongs"]["FontStyle"]); // 字體樣式
|
||||
@ -273,7 +308,7 @@ namespace DualScreenDemo
|
||||
// 設定輸入框的位置與大小
|
||||
ResizeAndPositionControl(inputBoxPinYinSongs, x, y, width, height);
|
||||
|
||||
// 綁定 `TextChanged` 事件 (當輸入內容改變時觸發搜尋)
|
||||
// **綁定 `TextChanged` 事件 (當輸入內容改變時觸發搜尋)**
|
||||
inputBoxPinYinSongs.TextChanged += (sender, e) =>
|
||||
{
|
||||
string searchText = inputBoxPinYinSongs.Text;
|
||||
@ -298,11 +333,22 @@ namespace DualScreenDemo
|
||||
// 發生錯誤時輸出錯誤訊息 (避免程式崩潰)
|
||||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
// 讀取 PictureBoxPinYinSongs 的座標設定
|
||||
/// <summary>
|
||||
/// 存儲 `PictureBoxPinYinSongs` 的座標與尺寸信息。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 此元組包含以下四個值:
|
||||
/// X:X 座標
|
||||
/// , Y:Y 座標
|
||||
/// , Width:寬度
|
||||
/// , Height:高度
|
||||
/// </remarks>
|
||||
private (int X, int Y, int Width, int Height) pictureBoxPinYinSongCoords;
|
||||
|
||||
/// <summary>
|
||||
/// 從 `config.ini` 配置檔案中載入 `PictureBoxPinYinSongs` 的座標與尺寸設定。
|
||||
/// </summary>
|
||||
private void LoadPictureBoxPinYinSongCoordsFromConfig()
|
||||
{
|
||||
// 創建一個 INI 檔案解析器
|
||||
@ -322,7 +368,10 @@ namespace DualScreenDemo
|
||||
int.Parse(coords["Height"]) // 解析 高度
|
||||
);
|
||||
}
|
||||
// 顯示拼音歌曲圖片
|
||||
/// <summary>
|
||||
/// 顯示拼音歌曲圖片
|
||||
/// </summary>
|
||||
/// <param name="imagePath">圖片路徑</param>
|
||||
private void ShowImageOnPictureBoxPinYinSongs(string imagePath)
|
||||
{
|
||||
// 從設定檔載入 PictureBox 的座標與大小
|
||||
@ -355,7 +404,10 @@ namespace DualScreenDemo
|
||||
pictureBoxPinYinSongs.Visible = true;
|
||||
|
||||
}
|
||||
// 設定拼音模式的 UI 是否可見
|
||||
/// <summary>
|
||||
/// 設定拼音模式的 UI 是否可見
|
||||
/// </summary>
|
||||
/// <param name="isVisible">是否可見</param>
|
||||
private void SetPinYinSongsAndButtonsVisibility(bool isVisible)
|
||||
{
|
||||
// 定義一個委派 (Action),用於更新 UI 控件的可見性
|
||||
|
Reference in New Issue
Block a user