295 lines
12 KiB
C#
295 lines
12 KiB
C#
using System.IO;
|
|
|
|
namespace DualScreenDemo
|
|
{
|
|
public partial class PrimaryForm
|
|
{
|
|
private PictureBox pictureBoxEnglishSongs;
|
|
private Button[] numberButtonsForSongs;
|
|
private Button[] letterButtonsForEnglishSongs;
|
|
private int[] ButtonsNumberSymbols = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
|
private string[] ButtonsEnglishSymbols = ["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"];
|
|
private Button modifyButtonEnglishSongs;
|
|
private Button clearButtonEnglishSongs;
|
|
private Button closeButtonEnglishSongs;
|
|
private RichTextBox inputBoxEnglishSongs;
|
|
|
|
private void InitializeButtonsForEnglishSongs()
|
|
{
|
|
InitializeInputBoxEnglishSongs();
|
|
InitializeEngAlphbtBtns(pictureBoxEnglishSongs,LetterButtonEnglishSongs_Click);
|
|
InitializeEngSongsButton();
|
|
}
|
|
|
|
private void InitializeEngSongsButton()
|
|
{
|
|
var data = LoadBtnConfigData();
|
|
|
|
modifyButtonEnglishSongs = new Button { Name = "modifyButtonEnglishSongs" };
|
|
ConfigureButton(modifyButtonEnglishSongs, 650, 275, 72, 67,
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesEnglish"]["normal"])),
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesEnglish"]["mouseOver"])),
|
|
new Bitmap(Path.Combine(serverPath, data["ModifyButtonImagesEnglish"]["mouseDown"])),
|
|
ModifyButtonEnglishSongs_Click);
|
|
|
|
pictureBoxEnglishSongs.Controls.Add(modifyButtonEnglishSongs);
|
|
|
|
|
|
clearButtonEnglishSongs = new Button { Name = "clearButtonEnglishSongs" };
|
|
ConfigureButton(clearButtonEnglishSongs, 8, 275, 72, 67,
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesEnglish"]["normal"])),
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesEnglish"]["mouseOver"])),
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesEnglish"]["mouseDown"])),
|
|
ClearButtonEnglishSongs_Click);
|
|
|
|
pictureBoxEnglishSongs.Controls.Add(clearButtonEnglishSongs);
|
|
|
|
|
|
closeButtonEnglishSongs = new Button { Name = "closeButtonEnglishSongs" };
|
|
ConfigureButton(closeButtonEnglishSongs, 730, 275, 72, 67,
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesEnglish"]["normal"])),
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesEnglish"]["mouseOver"])),
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesEnglish"]["mouseDown"])),
|
|
CloseButtonEnglishSongs_Click);
|
|
|
|
pictureBoxEnglishSongs.Controls.Add(closeButtonEnglishSongs);
|
|
}
|
|
private void InitializeEngAlphbtBtns(Control control, EventHandler handler)
|
|
{
|
|
numberButtonsForSongs = new Button[10];
|
|
letterButtonsForEnglishSongs = new Button[26];
|
|
// 設置上排按鈕
|
|
int x = 8;
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
CreateNumberBtns(i, x, 65, control, handler);
|
|
x += 80;
|
|
}
|
|
|
|
x = 8;
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
CreateEngAlphbtBtns(i, x, 135, control, handler);
|
|
x += 80;
|
|
}
|
|
|
|
x = 40;
|
|
for (int i = 10; i < 19; i++)
|
|
{
|
|
CreateEngAlphbtBtns(i, x, 205, control, handler);
|
|
x += 80;
|
|
}
|
|
// 設置下排按鈕
|
|
x = 88;
|
|
for (int i = 19; i < 26; i++)
|
|
{
|
|
CreateEngAlphbtBtns(i, x, 275, control, handler);
|
|
x += 80;
|
|
}
|
|
}
|
|
private void CreateEngAlphbtBtns(int index, int x, int y, Control control, EventHandler handler)
|
|
{
|
|
try
|
|
{
|
|
// 加載配置數據
|
|
var data = LoadBtnConfigData();
|
|
// 創建語音按鈕並設置其屬性
|
|
letterButtonsForEnglishSongs[index] = new Button
|
|
{
|
|
Name = $"ButtonsForEnglish_{ButtonsEnglishSymbols[index]}", // 按鈕名稱設為語音符號名稱
|
|
};
|
|
|
|
ConfigureButton(letterButtonsForEnglishSongs[index], x, y, 72, 67,
|
|
new Bitmap(Path.Combine(serverPath, data["EnglishLetterButtonImages"][$"button{index}_normal"])),
|
|
new Bitmap(Path.Combine(serverPath, data["EnglishLetterButtonImages"][$"button{index}_mouseOver"])),
|
|
new Bitmap(Path.Combine(serverPath, data["EnglishLetterButtonImages"][$"button{index}_mouseDown"])),
|
|
handler);
|
|
|
|
// 設置按鈕的 Tag 屬性為對應的語音符號
|
|
letterButtonsForEnglishSongs[index].Tag = ButtonsEnglishSymbols[index];
|
|
|
|
// 將按鈕添加到表單的控制項集合中
|
|
control.Controls.Add(letterButtonsForEnglishSongs[index]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error creating button at index {index}: {ex.Message}");
|
|
}
|
|
}
|
|
private void CreateNumberBtns(int index, int x, int y, Control control, EventHandler handler)
|
|
{
|
|
try
|
|
{
|
|
// 加載配置數據
|
|
var data = LoadBtnConfigData();
|
|
// 創建語音按鈕並設置其屬性
|
|
numberButtonsForSongs[index] = new Button
|
|
{
|
|
Name = $"ButtonsForEnglish_{ButtonsNumberSymbols[index]}", // 按鈕名稱設為語音符號名稱
|
|
};
|
|
|
|
ConfigureButton(numberButtonsForSongs[index], x, y, 72, 67,
|
|
new Bitmap(Path.Combine(serverPath, data["NumberButtonImages"][$"button{index}_normal"])),
|
|
new Bitmap(Path.Combine(serverPath, data["NumberButtonImages"][$"button{index}_mouseOver"])),
|
|
new Bitmap(Path.Combine(serverPath, data["NumberButtonImages"][$"button{index}_mouseDown"])),
|
|
handler);
|
|
|
|
// 設置按鈕的 Tag 屬性為對應的語音符號
|
|
numberButtonsForSongs[index].Tag = ButtonsNumberSymbols[index];
|
|
|
|
// 將按鈕添加到表單的控制項集合中
|
|
control.Controls.Add(numberButtonsForSongs[index]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error creating button at index {index}: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void InitializeInputBoxEnglishSongs()
|
|
{ /* 英文輸入介面設定,參考 config.ini */
|
|
try
|
|
{
|
|
string fontName = "Times New Roman";
|
|
float fontSize = 26;
|
|
FontStyle fontStyle = FontStyle.Regular;
|
|
Color foreColor = Color.Black;
|
|
|
|
inputBoxEnglishSongs = new RichTextBox
|
|
{
|
|
Visible = false,
|
|
Name = "inputBoxEnglishSongs",
|
|
ForeColor = foreColor,
|
|
Font = new Font(fontName, fontSize / 900 * Screen.PrimaryScreen.Bounds.Height, fontStyle)
|
|
};
|
|
|
|
ResizeAndPositionControl(inputBoxEnglishSongs, 10, 12, 455, 47);
|
|
|
|
pictureBoxEnglishSongs.Controls.Add(inputBoxEnglishSongs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"An error occurred: {ex.Message}");
|
|
}
|
|
}
|
|
/* 圖片位置設置 */
|
|
private void ShowImageOnPictureBoxEnglishSongs(string imagePath)
|
|
{
|
|
try
|
|
{
|
|
|
|
Bitmap originalImage = new Bitmap(imagePath);
|
|
|
|
pictureBoxEnglishSongs.Image = originalImage;
|
|
|
|
ResizeAndPositionPictureBox(pictureBoxEnglishSongs, 390, 360, 808, 356);
|
|
|
|
pictureBoxEnglishSongs.Visible = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"An error occurred: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void SetEnglishSongsAndButtonsVisibility(bool isVisible)
|
|
{
|
|
System.Action action = () =>
|
|
{
|
|
SuspendLayout();
|
|
if (isVisible) SetUIVisible(pictureBoxEnglishSongs);
|
|
else CloseUI(pictureBoxEnglishSongs);
|
|
ResumeLayout();
|
|
PerformLayout();
|
|
};
|
|
|
|
if (pictureBoxEnglishSongs.InvokeRequired)
|
|
{
|
|
pictureBoxEnglishSongs.Invoke(action);
|
|
}
|
|
else
|
|
{
|
|
action();
|
|
}
|
|
}
|
|
|
|
private void EnglishSearchSongsButton_Click(object sender, EventArgs e)
|
|
{
|
|
zhuyinSearchSongButton.BackgroundImage = zhuyinSearchSongNormalBackground;
|
|
englishSearchSongButton.BackgroundImage = englishSearchSongActiveBackground;
|
|
pinyinSearchSongButton.BackgroundImage = pinyinSearchSongNormalBackground;
|
|
wordCountSearchSongButton.BackgroundImage = wordCountSearchSongNormalBackground;
|
|
handWritingSearchSongButton.BackgroundImage = handWritingSearchSongNormalBackground;
|
|
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
|
|
|
|
var configData = LoadBtnConfigData();
|
|
string imagePath = Path.Combine(serverPath, configData["ImagePaths"]["EnglishSongs"]);
|
|
|
|
ShowImageOnPictureBoxEnglishSongs(Path.Combine(serverPath, imagePath));
|
|
// 鍵盤UI介面顯示設定
|
|
SetWordCountSongsAndButtonsVisibility(false);
|
|
SetEnglishSongsAndButtonsVisibility(true);
|
|
SetPinYinSongsAndButtonsVisibility(false);
|
|
SetHandWritingForSongsAndButtonsVisibility(false);
|
|
SetSongIDSearchAndButtonsVisibility(false);
|
|
SetZhuYinSongsAndButtonsVisibility(false);
|
|
|
|
ResetinputBox();
|
|
pictureBoxEnglishSongs.Visible = true;
|
|
}
|
|
private void LetterButtonEnglishSongs_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
var button = sender as Button;
|
|
if (button != null && button.Tag != null)
|
|
{
|
|
if (inputBoxEnglishSongs.Visible)
|
|
{
|
|
inputBoxEnglishSongs.Text += button.Tag.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ModifyButtonEnglishSongs_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (pictureBoxEnglishSongs.Controls.Contains(inputBoxEnglishSongs) && inputBoxEnglishSongs.Text.Length > 0)
|
|
{
|
|
inputBoxEnglishSongs.Text = inputBoxEnglishSongs.Text.Substring(0, inputBoxEnglishSongs.Text.Length - 1);
|
|
}
|
|
}
|
|
private void ClearButtonEnglishSongs_Click(object sender, EventArgs e)
|
|
{
|
|
if (pictureBoxEnglishSongs.Controls.Contains(inputBoxEnglishSongs) && inputBoxEnglishSongs.Text.Length > 0)
|
|
{
|
|
inputBoxEnglishSongs.Text = "";
|
|
}
|
|
}
|
|
private void CloseButtonEnglishSongs_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
pictureBoxEnglishSongs.Visible = false;
|
|
englishSearchSongButton.BackgroundImage = englishSearchSongNormalBackground;
|
|
SetEnglishSongsAndButtonsVisibility(false);
|
|
FindEnglishSongs();
|
|
}
|
|
private void FindEnglishSongs()
|
|
{
|
|
string searchText = inputBoxEnglishSongs.Text;
|
|
// 檢查是否為空字串或空白字元
|
|
string query = string.IsNullOrWhiteSpace(searchText)
|
|
? "SELECT * FROM song_library_cache ORDER BY song_id DESC LIMIT 1000;"
|
|
: $"SELECT * FROM song_library_cache WHERE song_name LIKE '{searchText}%' ORDER BY song_name DESC;";
|
|
|
|
var searchResults = SearchSongs_Mysql(query);
|
|
// 重置分頁
|
|
currentPage = 0;
|
|
totalPages = (int)Math.Ceiling((double)searchResults.Count / itemsPerPage);
|
|
// 更新多頁面面板的內容
|
|
multiPagePanel.currentPageIndex = 0;
|
|
multiPagePanel.LoadSongs(searchResults);
|
|
}
|
|
}
|
|
} |