进度条点击=>更改当前曲目播放位置

发布于 2024-09-29 05:12:27 字数 125 浏览 3 评论 0原文

我正在winforms 中制作一个音乐播放器。我有一个进度条,当我单击进度条上的某个位置时,我想获取该位置的整数(从 1 到 100,即当我想要到达歌曲中的某个点时)。我怎样才能做到这一点?

问候, 亚历山德鲁·巴德斯库

i am making a music player in winforms. i have a progress bar and when i click on a position along the progress bar, i want to get the int for that position ( from 1 to 100 , i.e. for when i want to get to a certain point in my song ) . How can i do that ?

Regards,
Alexandru Badescu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冬天旳寂寞 2024-10-06 05:12:27

使用 TrackBar 控件,以及 可能是一篇高级文章,希望对您有所帮助。

祝你好运。

Use TrackBar control, and this is may an advance one, I hope it helps you.

Good luck.

赠佳期 2024-10-06 05:12:27

试试这个:

'Using The Click or MouseDown or any Mouse Event

Dim Value As Integer= Me.PointToClient(MousePosition).X-Progressbar.Bounds.X

Progressbar.value= Value

Try this:

'Using The Click or MouseDown or any Mouse Event

Dim Value As Integer= Me.PointToClient(MousePosition).X-Progressbar.Bounds.X

Progressbar.value= Value
青芜 2024-10-06 05:12:27

您可以使用必须放置在进度条上的控件——例如一个小子弹。
现在,如果您使用代码,

progressbar1.value=control.location.x/y

请将控件的名称放置在控件 x/y 决定坐标的位置。

请注意,您必须移动进度条上的控件以进行简化使用图片框并使用 keydown 事件将其并排移动

you can use a control that have to be placed on the progress bar --like a small bullet .
now if you use the code

progressbar1.value=control.location.x/y

place the name of the control at the position of control x/y decides the coordinates.

make a note that you have to move the control on the progress bar for simplifications use a picture box and use the keydown event to move it side by side

表情可笑 2024-10-06 05:12:27

该值会显示一个与进度条上单击位置相关的值。这里的取值范围是从0到100%计算的。它还与进度条的宽度有关,因此范围将保持固定为百分比逻辑。

private void progressBar1_Click(object sender, EventArgs e)
        {
            // Get mouse position(x) minus the width of the progressbar (so beginning of the progressbar is mousepos = 0 //
            float absoluteMouse = (PointToClient(MousePosition).X - progressBar1.Bounds.X);
            // Calculate the factor for converting the position (progbarWidth/100) //
            float calcFactor = progressBar1.Width / (float)progressBar1.Maximum;
            // In the end convert the absolute mouse value to a relative mouse value by dividing the absolute mouse by the calcfactor //
            float relativeMouse = absoluteMouse / calcFactor;

            // Set the calculated relative value to the progressbar //
            progressBar1.Value = Convert.ToInt32(relativeMouse);
        }

我知道这个问题很久以前就被问过,但它没有正确的解决方案。现在就是这样。

This one brings up a value in relation to the position where the click was done on the progressbar. The value range here is calculated from 0 to 100%. Its also in relation to the width of the progressbar so the range will stay fixed to percentage logic.

private void progressBar1_Click(object sender, EventArgs e)
        {
            // Get mouse position(x) minus the width of the progressbar (so beginning of the progressbar is mousepos = 0 //
            float absoluteMouse = (PointToClient(MousePosition).X - progressBar1.Bounds.X);
            // Calculate the factor for converting the position (progbarWidth/100) //
            float calcFactor = progressBar1.Width / (float)progressBar1.Maximum;
            // In the end convert the absolute mouse value to a relative mouse value by dividing the absolute mouse by the calcfactor //
            float relativeMouse = absoluteMouse / calcFactor;

            // Set the calculated relative value to the progressbar //
            progressBar1.Value = Convert.ToInt32(relativeMouse);
        }

I know this question was asked a long time ago, but it was out of the right solution. Here it is now.

那伤。 2024-10-06 05:12:27

好吧,您可以使用图片框来模拟进度条...有一种方法可以根据当前进度部分填充它,并连接 MouseDown 事件(这将为您提供鼠标位置,然后您可以相应地缩放)。

Well you could use a picturebox to simulate a progress bar ... have a method to partially fill it based on current progress, and wire up the MouseDown event (this will provide you with the mouse position which you can then scale accordingly).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文