From f2d633e688d7164c73aa5a8ed472c344b3fea23d Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Fri, 20 Jun 2025 13:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=9F=B3=E6=95=88=E7=89=88?= =?UTF-8?q?=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrimaryFormParts/PrimaryForm.SoundEffects.cs | 95 +++++++++++++------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/PrimaryFormParts/PrimaryForm.SoundEffects.cs b/PrimaryFormParts/PrimaryForm.SoundEffects.cs index e1e473c..e38ba0e 100644 --- a/PrimaryFormParts/PrimaryForm.SoundEffects.cs +++ b/PrimaryFormParts/PrimaryForm.SoundEffects.cs @@ -1,6 +1,10 @@ +using System; +using System.Drawing; using System.IO; +using System.Windows.Forms; using NAudio.Wave; using WMPLib; +using System.Collections.Generic; namespace DualScreenDemo { @@ -21,6 +25,28 @@ namespace DualScreenDemo { mediaPlayer = new WindowsMediaPlayer(); } + private void ConfigureImageButton(Button button, int posX, int posY, int width, int height, + string imagePath, EventHandler clickEventHandler) + { + Bitmap image = new Bitmap(imagePath); + button.SetBounds(posX, posY, image.Width, image.Height); + + // 載入圖片 + button.BackgroundImage = image; + button.BackgroundImageLayout = ImageLayout.Stretch; + + // 按鈕樣式設定 + button.FlatStyle = FlatStyle.Flat; + button.FlatAppearance.BorderSize = 0; + button.FlatAppearance.MouseDownBackColor = Color.Transparent; + button.FlatAppearance.MouseOverBackColor = Color.Transparent; + + // 點擊事件 + if (clickEventHandler != null) + button.Click += clickEventHandler; + + this.Controls.Add(button); + } private void InitializeSoundEffectButtons() { @@ -29,9 +55,9 @@ namespace DualScreenDemo { Name = "constructionButton", }; - ConfigureButton(constructionButton, 876, 494, 148, 64, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - ConstructionButton_Click); + string path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_工地.png"); + ConfigureImageButton(constructionButton, 1183, 634, 148, 64, + path, ConstructionButton_Click); this.Controls.Add(constructionButton); @@ -39,9 +65,9 @@ namespace DualScreenDemo { Name = "marketButton", }; - ConfigureButton(marketButton, 1037, 495, 148, 63, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - MarketButton_Click); + path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_市場.png"); + ConfigureImageButton(marketButton, 1394, 634, 148, 63, + path, MarketButton_Click); this.Controls.Add(marketButton); @@ -49,9 +75,9 @@ namespace DualScreenDemo { Name = "drivingButton", }; - ConfigureButton(drivingButton, 876, 570, 148, 63, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - DrivingButton_Click); + path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_開車.png"); + ConfigureImageButton(drivingButton, 1183, 720, 148, 63, + path, DrivingButton_Click); this.Controls.Add(drivingButton); @@ -59,9 +85,9 @@ namespace DualScreenDemo { Name = "airportButton", }; - ConfigureButton(airportButton, 1037, 570, 148, 63, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - AirportButton_Click); + path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_機場.png"); + ConfigureImageButton(airportButton, 1394, 720, 148, 63, + path, AirportButton_Click); this.Controls.Add(airportButton); @@ -69,9 +95,9 @@ namespace DualScreenDemo { Name = "officeButton", }; - ConfigureButton(officeButton, 876, 646, 148, 64, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - OfficeButton_Click); + path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_辦公室.png"); + ConfigureImageButton(officeButton, 1183, 806, 148, 64, + path, OfficeButton_Click); this.Controls.Add(officeButton); @@ -79,10 +105,9 @@ namespace DualScreenDemo { Name = "closeButton", }; - - ConfigureButton(closeButton, 1036, 646, 150, 63, - resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, - CloseButton_Click); + path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_關閉.png"); + ConfigureImageButton(closeButton, 1394, 806, 150, 63, + path, CloseButton_Click); this.Controls.Add(closeButton); } @@ -96,7 +121,7 @@ namespace DualScreenDemo if (!pictureBoxSceneSoundEffects.Visible) { - ShowImageOnPictureBoxSceneSoundEffects(Path.Combine(Application.StartupPath, @"themes\superstar\555022.jpg")); + ShowImageOnPictureBoxSceneSoundEffects(Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效.png")); SetPictureBoxSceneSoundEffectsAndButtonsVisibility(true); } else @@ -131,28 +156,30 @@ namespace DualScreenDemo public void PlayApplauseSound() { - mediaPlayer.URL = Path.Combine(Application.StartupPath, "sounds", "zs.m4a"); + mediaPlayer.URL = Path.Combine(Application.StartupPath,"sounds" ,"zs.m4a"); mediaPlayer.controls.play(); } - + // 按鈕位置需要更改,底圖需要更改 private void ShowImageOnPictureBoxSceneSoundEffects(string imagePath) { - Bitmap originalImage = new Bitmap(imagePath); + if (File.Exists(imagePath)) + { + // 直接載入完整圖 + Bitmap image = new Bitmap(imagePath); - - Rectangle cropArea = new Rectangle(859, 427, 342, 295); + // 顯示在 PictureBox 上 + pictureBoxSceneSoundEffects.Image = image; - - Bitmap croppedImage = CropImage(originalImage, cropArea); + // 設定 PictureBox 的大小與位置(依你的需要調整) + ResizeAndPositionPictureBox(pictureBoxSceneSoundEffects, 850, 450, image.Width , image.Height); - - pictureBoxSceneSoundEffects.Image = croppedImage; - - - ResizeAndPositionPictureBox(pictureBoxSceneSoundEffects, cropArea.X, cropArea.Y, cropArea.Width, cropArea.Height); - - pictureBoxSceneSoundEffects.Visible = true; + pictureBoxSceneSoundEffects.Visible = true; + } + else + { + Console.WriteLine("圖片檔案不存在:" + imagePath); + } } private void TogglePictureBoxSceneSoundEffectsButtonsVisibility()