From 6a9b2956dedb5217cae1d4a6ade6f168b20f36f6 Mon Sep 17 00:00:00 2001 From: Janco Kock Date: Sat, 31 Oct 2015 16:09:44 +0100 Subject: [PATCH] Fixed seeking on specific click on trackbar --- MusicPlayer/MusicPlayer/MainForm.Designer.cs | 7 ++++--- MusicPlayer/MusicPlayer/MainForm.cs | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MusicPlayer/MusicPlayer/MainForm.Designer.cs b/MusicPlayer/MusicPlayer/MainForm.Designer.cs index dc11844..6a59bfd 100644 --- a/MusicPlayer/MusicPlayer/MainForm.Designer.cs +++ b/MusicPlayer/MusicPlayer/MainForm.Designer.cs @@ -324,7 +324,7 @@ namespace MusicPlayer this.PlayNextSongButton.CheckOnClick = true; this.PlayNextSongButton.CheckState = System.Windows.Forms.CheckState.Checked; this.PlayNextSongButton.Name = "PlayNextSongButton"; - this.PlayNextSongButton.Size = new System.Drawing.Size(152, 22); + this.PlayNextSongButton.Size = new System.Drawing.Size(123, 22); this.PlayNextSongButton.Text = "Play Next"; // // LoopSongButton @@ -333,7 +333,7 @@ namespace MusicPlayer this.LoopSongButton.CheckOnClick = true; this.LoopSongButton.CheckState = System.Windows.Forms.CheckState.Checked; this.LoopSongButton.Name = "LoopSongButton"; - this.LoopSongButton.Size = new System.Drawing.Size(152, 22); + this.LoopSongButton.Size = new System.Drawing.Size(123, 22); this.LoopSongButton.Text = "Loop"; // // ShuffleSongButton @@ -341,7 +341,7 @@ namespace MusicPlayer this.ShuffleSongButton.CheckOnClick = true; this.ShuffleSongButton.Enabled = false; this.ShuffleSongButton.Name = "ShuffleSongButton"; - this.ShuffleSongButton.Size = new System.Drawing.Size(152, 22); + this.ShuffleSongButton.Size = new System.Drawing.Size(123, 22); this.ShuffleSongButton.Text = "Shuffle"; // // playlistToolStripMenuItem @@ -500,6 +500,7 @@ namespace MusicPlayer this.PositionTrackBar.Size = new System.Drawing.Size(778, 45); this.PositionTrackBar.TabIndex = 7; this.PositionTrackBar.TickStyle = System.Windows.Forms.TickStyle.None; + this.PositionTrackBar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PositionTrackBar_MouseDown); // // BufferLabel // diff --git a/MusicPlayer/MusicPlayer/MainForm.cs b/MusicPlayer/MusicPlayer/MainForm.cs index 4021028..5bbc67b 100644 --- a/MusicPlayer/MusicPlayer/MainForm.cs +++ b/MusicPlayer/MusicPlayer/MainForm.cs @@ -377,5 +377,12 @@ namespace MusicPlayer SearchGenresTextBox.Text = ""; ClearGenreSearchButton.Enabled = false; } + + private void PositionTrackBar_MouseDown(object sender, MouseEventArgs e) + { + double dblValue; + dblValue = ((double)(e.X+PositionTrackBar.Location.X) / (double)(PositionTrackBar.Width + PositionTrackBar.Location.X)) * (PositionTrackBar.Maximum - PositionTrackBar.Minimum); + PositionTrackBar.Value = Convert.ToInt32(dblValue); + } } }