Naudio GUI song position Slider problem

Aug 14, 2013 at 7:02 AM
HI Mark,
 I use naudio gui component SongPositionSlider as a my song trackbar. But problem is that after some time interval it's vibrate.
``` This is my SongPositionSlider.cs class

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace NAudio.Gui
{
/// <summary>
/// VolumeSlider control
/// </summary>
public class SongPositionSlider : System.Windows.Forms.UserControl
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private int _SongLength = 0;
    private int _CuttentTime = 0;
    private float MinDb =-20;// -48;
    private int currentVolumn = 582;
    /// <summary>
    /// Volume changed event
    /// </summary>
    public event EventHandler VolumeChanged;

    /// <summary>
    /// Creates a new VolumeSlider control
    /// </summary>
    public SongPositionSlider()
    {
        // This call is required by the Windows.Forms Form Designer.
        InitializeComponent();

        // TODO: Add any initialization after the InitComponent call
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (components != null)
                components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Component Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // SongPositionSlider
        // 
        this.BackColor = System.Drawing.Color.Transparent;
        this.Name = "SongPositionSlider";
        this.Size = new System.Drawing.Size(96, 16);
        this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// <see cref="Control.OnPaint"/>
    /// </summary>
    protected override void OnPaint(PaintEventArgs pe)
    {
        //int _PaintWidth = 0;
        //if (_SongLength > 0)
        //{
        //    _PaintWidth = (int)((_CuttentTime * 580) / _SongLength);
        //}

        pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0, 0, 0)), 0, 0, _CuttentTime, this.Height);

        // Calling the base class OnPaint
        //base.OnPaint(pe);
        pe.Graphics.Dispose();
    }

    /// <summary>
    /// <see cref="Control.OnMouseMove"/>
    /// </summary>
    protected override void OnMouseMove(MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            SetVolumeFromMouse(e.X);
        }
        base.OnMouseMove(e);
    }

    /// <summary>
    /// <see cref="Control.OnMouseDown"/>
    /// </summary>
    protected override void OnMouseDown(MouseEventArgs e)
    {
        SetVolumeFromMouse(e.X);
        base.OnMouseDown(e);
    }

    private void SetVolumeFromMouse(int x)
    {
        //currentVolumn = x;
        //// linear Volume = (float) x / this.Width;
        //float dbVolume = (1 - (float)x / this.Width) * MinDb;
        //if (x <= 0)
        //    Volume = 0;
        //else
        //    Volume = (float)Math.Pow(10, dbVolume / 20);
        CuttentTime = x;
    }

    /// <summary>
    /// The volume for this control
    /// </summary>
    [DefaultValue(0)]
    public int SongLength
    {
        get
        {
            return _SongLength;
        }
        set
        {
            _SongLength = value;
        }
    }

    [DefaultValue(0)]
    public int CuttentTime
    {
        get
        {
            return _CuttentTime;
        }
        set
        {
            _CuttentTime = value;
            if (VolumeChanged != null)
                VolumeChanged(this, EventArgs.Empty);
            Invalidate();
        }
    }
}
}

```HOw can i solved my problem?pls i wait for your help.