2025-04-07 16:54:10 +08:00
|
|
|
using System.IO;
|
|
|
|
using Microsoft.Ink;
|
|
|
|
|
|
|
|
namespace DualScreenDemo
|
|
|
|
{
|
|
|
|
public partial class PrimaryForm
|
|
|
|
{
|
|
|
|
private PictureBox pictureBoxHandWritingSingers;
|
|
|
|
private Button refillButtonHandWritingSingers;
|
|
|
|
private Button clearButtonHandWritingSingers;
|
|
|
|
private Button closeButtonForSingers;
|
|
|
|
private Panel handWritingPanelForSingers;
|
|
|
|
private InkOverlay inkOverlayForSingers;
|
|
|
|
private RichTextBox handwritingInputBoxForSingers;
|
|
|
|
private ListBox candidateListBoxForSingers;
|
|
|
|
|
|
|
|
|
|
|
|
private void InitializeHandWritingForSingers()
|
|
|
|
{
|
|
|
|
InitializeHandWritingPanelForSingers();
|
|
|
|
InitializeInkOverlayForSingers();
|
|
|
|
InitializeHandwritingInputBoxForSingers();
|
|
|
|
InitializeCandidateListBoxForSingers();
|
2025-08-28 17:49:07 +08:00
|
|
|
InitializeBtnsHandwritingSingers();
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
private void InitializeHandWritingPanelForSingers()
|
|
|
|
{
|
|
|
|
handWritingPanelForSingers = new Panel
|
|
|
|
{
|
|
|
|
BorderStyle = BorderStyle.FixedSingle,
|
2025-08-28 17:49:07 +08:00
|
|
|
BackColor = Color.WhiteSmoke,
|
|
|
|
Visible = false
|
2025-04-07 16:54:10 +08:00
|
|
|
};
|
2025-08-28 17:49:07 +08:00
|
|
|
ResizeAndPositionControl(handWritingPanelForSingers, 20, 89, 650, 260);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
pictureBoxHandWritingSingers.Controls.Add(handWritingPanelForSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void InitializeInkOverlayForSingers()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
inkOverlayForSingers = new InkOverlay(handWritingPanelForSingers);
|
|
|
|
inkOverlayForSingers.Enabled = false;
|
|
|
|
inkOverlayForSingers.Ink = new Ink();
|
|
|
|
inkOverlayForSingers.DefaultDrawingAttributes.Color = Color.Black;
|
|
|
|
inkOverlayForSingers.DefaultDrawingAttributes.Width = 100;
|
|
|
|
inkOverlayForSingers.Stroke += new InkCollectorStrokeEventHandler(InkOverlayForSingers_Stroke);
|
|
|
|
|
|
|
|
inkOverlayForSingers.Enabled = true;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Failed to initialize ink overlay for singers: " + ex.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InkOverlayForSingers_Stroke(object sender, InkCollectorStrokeEventArgs e)
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
RecognizeInk(inkOverlayForSingers, candidateListBoxForSingers);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InitializeHandwritingInputBoxForSingers()
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
handwritingInputBoxForSingers = new RichTextBox
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
|
2025-04-07 16:54:10 +08:00
|
|
|
Visible = false
|
|
|
|
};
|
2025-08-28 17:49:07 +08:00
|
|
|
ResizeAndPositionControl(handwritingInputBoxForSingers, 20, 12, 541, 64);
|
|
|
|
pictureBoxHandWritingSingers.Controls.Add(handwritingInputBoxForSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
}
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
private void InitializeCandidateListBoxForSingers()
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
candidateListBoxForSingers = new ListBox
|
|
|
|
{
|
|
|
|
Font = new Font("微軟正黑體", (float)26 / 900 * Screen.PrimaryScreen.Bounds.Height, FontStyle.Regular),
|
|
|
|
Visible = false
|
|
|
|
};
|
2025-08-28 17:49:07 +08:00
|
|
|
ResizeAndPositionControl(candidateListBoxForSingers, 675, 81, 115, 270);
|
2025-04-07 16:54:10 +08:00
|
|
|
candidateListBoxForSingers.SelectedIndexChanged += CandidateListBoxForSingers_SelectedIndexChanged;
|
2025-08-28 17:49:07 +08:00
|
|
|
pictureBoxHandWritingSingers.Controls.Add(candidateListBoxForSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void CandidateListBoxForSingers_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (candidateListBoxForSingers.SelectedIndex != -1)
|
|
|
|
{
|
|
|
|
string selectedWord = candidateListBoxForSingers.SelectedItem.ToString();
|
2025-08-28 17:49:07 +08:00
|
|
|
handwritingInputBoxForSingers.Text += selectedWord;
|
|
|
|
candidateListBoxForSingers.Visible = false;
|
|
|
|
|
|
|
|
|
2025-04-07 16:54:10 +08:00
|
|
|
if (inkOverlayForSingers != null)
|
|
|
|
{
|
|
|
|
inkOverlayForSingers.Ink.DeleteStrokes();
|
2025-08-28 17:49:07 +08:00
|
|
|
handWritingPanelForSingers.Invalidate();
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ShowImageOnPictureBoxHandWritingSingers(string imagePath)
|
|
|
|
{
|
|
|
|
Bitmap originalImage = new Bitmap(imagePath);
|
|
|
|
|
|
|
|
pictureBoxHandWritingSingers.Image = originalImage;
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
ResizeAndPositionPictureBox(pictureBoxHandWritingSingers, 388, 355, 810, 360);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
pictureBoxHandWritingSingers.Visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetHandWritingForSingersAndButtonsVisibility(bool isVisible)
|
|
|
|
{
|
|
|
|
EnableDoubleBuffering(handWritingPanelForSingers);
|
|
|
|
EnableDoubleBuffering(handwritingInputBoxForSingers);
|
|
|
|
EnableDoubleBuffering(candidateListBoxForSingers);
|
|
|
|
EnableDoubleBuffering(pictureBoxHandWritingSingers);
|
|
|
|
EnableDoubleBuffering(refillButtonHandWritingSingers);
|
|
|
|
EnableDoubleBuffering(clearButtonHandWritingSingers);
|
|
|
|
EnableDoubleBuffering(closeButtonForSingers);
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
if (isVisible)SetUIVisible(pictureBoxHandWritingSingers);
|
|
|
|
else CloseUI(pictureBoxHandWritingSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
private void InitializeBtnsHandwritingSingers()
|
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
|
|
|
refillButtonHandWritingSingers = new Button
|
|
|
|
{
|
|
|
|
Name = "refillButtonHandWritingSingers",
|
|
|
|
};
|
|
|
|
ConfigureButton(refillButtonHandWritingSingers, 565, 12, 72, 66,
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["normal"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["mouseOver"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["RefillButtonImagesHandWriting"]["mouseDown"])),
|
|
|
|
RefillButtonHandWritingSingers_Click);
|
|
|
|
pictureBoxHandWritingSingers.Controls.Add(refillButtonHandWritingSingers);
|
|
|
|
|
|
|
|
clearButtonHandWritingSingers = new Button
|
|
|
|
{
|
|
|
|
Name = "clearButtonHandWritingSongs",
|
|
|
|
};
|
|
|
|
ConfigureButton(clearButtonHandWritingSingers, 642, 11, 72, 66,
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["normal"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["mouseOver"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["ClearButtonImagesHandWriting"]["mouseDown"])),
|
|
|
|
ClearButtonHandWritingSingers_Click);
|
|
|
|
pictureBoxHandWritingSingers.Controls.Add(clearButtonHandWritingSingers);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
closeButtonForSingers = new Button
|
|
|
|
{
|
|
|
|
Name = "closeButtonForSingers",
|
|
|
|
};
|
|
|
|
ConfigureButton(closeButtonForSingers, 719, 11, 72, 66,
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["normal"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["mouseOver"])),
|
|
|
|
new Bitmap(Path.Combine(serverPath, data["CloseButtonImagesHandWriting"]["mouseDown"])),
|
|
|
|
CloseButtonForSingers_Click);
|
|
|
|
pictureBoxHandWritingSingers.Controls.Add(closeButtonForSingers);
|
|
|
|
}
|
|
|
|
#region 按鈕點擊事件
|
|
|
|
private void HandWritingSearchButtonForSingers_Click(object sender, EventArgs e)
|
2025-04-07 16:54:10 +08:00
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
this.SuspendLayout();
|
|
|
|
|
|
|
|
UpdateSSearchBtn(handWritingSearchButton, handWritingSearchActiveBackground);
|
|
|
|
|
|
|
|
EnableDoubleBuffering(handWritingPanelForSingers);
|
|
|
|
EnableDoubleBuffering(handwritingInputBoxForSingers);
|
|
|
|
EnableDoubleBuffering(candidateListBoxForSingers);
|
|
|
|
EnableDoubleBuffering(pictureBoxHandWritingSingers);
|
|
|
|
EnableDoubleBuffering(refillButtonHandWritingSingers);
|
|
|
|
EnableDoubleBuffering(closeButtonForSingers);
|
|
|
|
|
|
|
|
|
|
|
|
var configData = LoadBtnConfigData();
|
|
|
|
string handWritingImagePath = Path.Combine(serverPath, configData["ImagePaths"]["HandWritingSingers"]);
|
|
|
|
|
|
|
|
ShowImageOnPictureBoxHandWritingSingers(Path.Combine(serverPath, handWritingImagePath));
|
|
|
|
SetZhuYinSingersAndButtonsVisibility(false);
|
|
|
|
SetEnglishSingersAndButtonsVisibility(false);
|
|
|
|
SetPinYinSingersAndButtonsVisibility(false);
|
|
|
|
SetWordCountSingersAndButtonsVisibility(false); // 隱藏字數搜尋相關控件
|
|
|
|
//SetPictureBoxArtistSearchAndButtonsVisibility(false);
|
|
|
|
SetHandWritingForSingersAndButtonsVisibility(true);
|
2025-04-07 16:54:10 +08:00
|
|
|
|
2025-08-28 17:49:07 +08:00
|
|
|
ResetinputBox();
|
|
|
|
this.ResumeLayout();
|
|
|
|
}
|
2025-04-07 16:54:10 +08:00
|
|
|
private void RefillButtonHandWritingSingers_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
handwritingInputBoxForSingers.Text = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClearButtonHandWritingSingers_Click(object sender, EventArgs e)
|
|
|
|
{
|
2025-09-02 17:38:58 +08:00
|
|
|
if (pictureBoxHandWritingSingers.Controls.Contains(handWritingPanelForSingers) && inkOverlayForSingers != null)
|
2025-04-07 16:54:10 +08:00
|
|
|
{
|
|
|
|
inkOverlayForSingers.Ink.DeleteStrokes();
|
2025-08-28 17:49:07 +08:00
|
|
|
handWritingPanelForSingers.Invalidate();
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private void CloseButtonForSingers_Click(object sender, EventArgs e)
|
|
|
|
{
|
2025-08-28 17:49:07 +08:00
|
|
|
|
2025-09-02 17:38:58 +08:00
|
|
|
pictureBoxHandWritingSingers.SuspendLayout();
|
2025-04-07 16:54:10 +08:00
|
|
|
|
|
|
|
SetHandWritingForSingersAndButtonsVisibility(false);
|
|
|
|
handWritingSearchButton.BackgroundImage = handWritingSearchNormalBackground;
|
2025-04-14 11:28:41 +08:00
|
|
|
FindHandwritingSingers();
|
2025-09-02 17:38:58 +08:00
|
|
|
pictureBoxHandWritingSingers.ResumeLayout();
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
private void FindHandwritingSingers()
|
|
|
|
{
|
|
|
|
string searchText = handwritingInputBoxForSingers.Text;
|
|
|
|
string query = string.IsNullOrWhiteSpace(searchText)
|
|
|
|
? "SELECT * FROM artists LIMIT 1000;"
|
|
|
|
: $"SELECT * FROM artists WHERE `name` 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);
|
2025-04-14 11:28:41 +08:00
|
|
|
}
|
2025-08-28 17:49:07 +08:00
|
|
|
#endregion
|
2025-04-07 16:54:10 +08:00
|
|
|
}
|
|
|
|
}
|