2508281333

已點歌曲頁面自動定位至播放中歌曲
QRCode關閉按鈕偏移問題修正
This commit is contained in:
jasonchenwork 2025-08-28 13:35:11 +08:00
parent 9e44419710
commit ed34f6c05a
3 changed files with 77 additions and 46 deletions

View File

@ -12,7 +12,7 @@ namespace DualScreenDemo
{
private const int ItemHeight = 70;
private const int RowGap = 2;
private int itemsPerPage
public int itemsPerPage
{
get
{
@ -204,11 +204,9 @@ namespace DualScreenDemo
currentArtistList.Clear();
currentPageIndex = 0;
totalPages = (int)Math.Ceiling(songs.Count / (double)itemsPerPage);
// 直接調用基礎刷新邏輯
RefreshDisplayBase();
}
public void LoadSingers(List<Artist> artists)
{
_isShowingSinger = true;
@ -219,18 +217,17 @@ namespace DualScreenDemo
RefreshDisplayBase_Singer();
}
public void LoadPlayedSongs(List<SongData> songs)
public void LoadPlayedSongs(List<SongData> songs,int page)
{
_isShowingSinger = false;
currentSongList = songs;
currentArtistList.Clear();
currentPageIndex = 0;
currentPageIndex = page;
totalPages = (int)Math.Ceiling(songs.Count / (double)itemsPerPage);
// 直接調用基礎刷新邏輯
RefreshDisplayBase();
}
public void RefreshDisplay()
{
this.Controls.Clear(); // 清除所有 UI 元件
@ -562,8 +559,6 @@ namespace DualScreenDemo
songLabel.BringToFront();
artistLabel.BringToFront();
//songLabel.Controls.Add(artistLabel);
//artistLabel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
songLabel.TextAlign = ContentAlignment.TopLeft;
}

View File

@ -92,8 +92,6 @@ namespace DualScreenDemo
closeQRCodeButton = new Button { Text = "" };
closeQRCodeButton.Name = "closeQRCodeButton";
closeQRCodeButton.Location = new Point(259, 7);
closeQRCodeButton.Size = new Size(30, 30);
closeQRCodeButton.BackColor = Color.Transparent;
closeQRCodeButton.BackgroundImageLayout = ImageLayout.Stretch;
closeQRCodeButton.FlatStyle = FlatStyle.Flat;
@ -102,6 +100,7 @@ namespace DualScreenDemo
closeQRCodeButton.FlatAppearance.MouseDownBackColor = Color.Transparent;
closeQRCodeButton.Click += CloseQRCodeButton_Click;
pictureBoxQRCode.Controls.Add(closeQRCodeButton);
ResizeAndPositionControl(closeQRCodeButton, 193, 4, 25, 25);
}
catch (Exception ex)
{

View File

@ -136,32 +136,32 @@ namespace DualScreenDemo
// string serverPath = Utils.Env.GetPath("", "");
string serverPath = Application.StartupPath;
// async Task<Bitmap> GetBitmapFromUriAsync(Uri uri)
// {
// using HttpClient client = new HttpClient();
// byte[] imageBytes = await client.GetByteArrayAsync(uri);
//async Task<Bitmap> GetBitmapFromUriAsync(Uri uri)
//{
// using HttpClient client = new HttpClient();
// byte[] imageBytes = await client.GetByteArrayAsync(uri);
// MemoryStream ms = new MemoryStream(imageBytes);
// Bitmap bitmap = new Bitmap(ms);
// Bitmap clonedBitmap = new Bitmap(bitmap);
// ms.Dispose();
// MemoryStream ms = new MemoryStream(imageBytes);
// Bitmap bitmap = new Bitmap(ms);
// Bitmap clonedBitmap = new Bitmap(bitmap);
// ms.Dispose();
// return clonedBitmap;
// }
// return clonedBitmap;
//}
// private async void LoadBackgroundImage()
// {
// var data = LoadBtnConfigData();
// var hostdata = LoadBtnConfigData();
// string test = hostdata["HeartBeatUrl"] + "/" + data["PrimaryFormBtn"]["AlertNormal1"];
// Console.WriteLine(test);
// Uri remoteUri = new Uri("http://zqd.superstar.dnsnet.cc/themes/superstar/button/1.主類別/主類別上方_新歌快報(未按).png");
//private async void LoadBackgroundImage()
//{
// var data = LoadBtnConfigData();
// var hostdata = LoadBtnConfigData();
// string test1 = hostdata["HeartBeatUrl"] + "/" + data["PrimaryFormBtn"]["AlertNormal1"];
// Console.WriteLine(test1);
// Uri remoteUri = new Uri("http://zqd.superstar.dnsnet.cc/themes/superstar/button/1.主類別/主類別上方_新歌快報(未按).png");
// Bitmap bitmap = await GetBitmapFromUriAsync(remoteUri);
// this.BackgroundImage = bitmap;
// this.BackgroundImageLayout = ImageLayout.Stretch; // Optional
// }
// Bitmap bitmap = await GetBitmapFromUriAsync(remoteUri);
// this.BackgroundImage = bitmap;
// this.BackgroundImageLayout = ImageLayout.Stretch; // Optional
//}
public int currentPage
{
@ -179,7 +179,7 @@ namespace DualScreenDemo
this.Invalidate(); // 重新繪製界面
}
public const int itemsPerPage = 18;
public const int itemsPerPage = 16;
private WaveInEvent waveIn;
private WaveFileWriter waveWriter;
@ -340,12 +340,12 @@ namespace DualScreenDemo
// 設定繪製文字的位置 (X=500, Y=30)
PointF point_PCName = new PointF(450 * scaleX, 30 * scaleY);
PointF point_PageNumber = new PointF(1390 * scaleX, 30 * scaleY);
PointF point_verSion = new PointF(1800 * scaleX, 30 * scaleY);
PointF point_verSion = new PointF(1800 * scaleX-10, 30 * scaleY);
// 繪製文字:
// `DrawString(要繪製的文字, 字型, 畫刷, 位置)`
e.Graphics.DrawString(displayName, font, brush, point_PCName);
e.Graphics.DrawString(pageNumber, font, brush, point_PageNumber);
e.Graphics.DrawString(version.Substring(version.IndexOf("V"), 4), font, brush, point_verSion);
e.Graphics.DrawString(version.Substring(version.IndexOf("V"), 5), font, brush, point_verSion);
}
private void User_Paint(object sender, PaintEventArgs e)
{
@ -2312,14 +2312,16 @@ namespace DualScreenDemo
{
var data = LoadBtnConfigData();
UpdateButtonBackgrounds(orderedSongsButton,orderedSongsActiveBackground);
UpdateButtonBackgrounds(orderedSongsButton, orderedSongsActiveBackground);
isOnOrderedSongsPage = true;
autoRefreshTimer.Start(); // 开始自动刷新
// 已點歌曲錨點
var List = SongList.GetHistory();
totalPages = (int)Math.Ceiling((double)List.Count / itemsPerPage);
multiPagePanel.currentPageIndex = 0;
int index = List.FindIndex(song => song.GetState() == PlayState.Playing);
int page = 0;
if ((index+1) > multiPagePanel.itemsPerPage) page = Math.Abs((index+1) / multiPagePanel.itemsPerPage);
SetHotSongButtonsVisibility(false);
SetNewSongButtonsVisibility(false);
@ -2343,7 +2345,7 @@ namespace DualScreenDemo
closeQRCodeButton.Visible = false;
}
multiPagePanel.LoadPlayedSongs(List);
multiPagePanel.LoadPlayedSongs(List,page);
}
#region Visible屬性設定
@ -2419,5 +2421,40 @@ namespace DualScreenDemo
activeButton.BackgroundImage = activeBackground;
}
private async void HttpDownload(string fileUrl,string LocalLoc)
{
using HttpClient client = new HttpClient();
try
{
var response= await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead);
var totalBytes = response.Content.Headers.ContentLength ?? -1L;
using var contentStream = await response.Content.ReadAsStreamAsync();
using var fileStream = new FileStream(LocalLoc, FileMode.Create, FileAccess.Write, FileShare.None);
var buffer = new byte[8192];
long totalRead = 0;
int read;
while ((read = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, read);
totalRead += read;
if (totalBytes > 0)
{
int progress = (int)((totalRead * 100) / totalBytes);
progressBar.Value = progress;
}
}
Console.WriteLine("File Downloaded");
}
catch (Exception ex)
{
Console.WriteLine("Download Failed:"+ex.Message);
Program.WriteLog("Download Failed:" + ex.Message);
}
}
}
}