public void SetValue(int value) { if (pb_color_bar.InvokeRequired) { valueChangeCallback a = new valueChangeCallback(SetValue); pb_color_bar.Invoke(a, value); } else { this.value = value; double perLength = (double)width / (double)maxValue; int location = (int)(perLength * value); circleLocation.X = location; pb_color_bar.Width = location; pb_circle.Location = circleLocation; RunCallback(); } }
public void AddValueChangeEvent(valueChangeCallback c) { callback = c; }
public Ye0junSeekbar(Panel root, int width, int maxValue) { callback = null; this.margin = 5; this.width = width; this.maxValue = maxValue; this.value = 0; bClick = false; parent = new Panel(); parent.Width = width + margin * 2; parent.Height = 9; root.Controls.Add(parent); root.Controls.SetChildIndex(parent, 0); touch = new TransparentPanel(); touch.Width = width + margin * 2; touch.Height = 9; touch.Visible = false; parent.Controls.Add(touch); parent.Controls.SetChildIndex(touch, 0); circleLocation = new Point(0, 0); pb_circle = new PictureBox(); pb_circle.Width = 9; pb_circle.Height = 9; pb_circle.Location = circleLocation; pb_circle.Image = Properties.Resources.circle; pb_circle.BackColor = Color.Transparent; parent.Controls.Add(pb_circle); pb_color_bar = new PictureBox(); pb_color_bar.Width = 50; pb_color_bar.Height = 1; pb_color_bar.Location = new Point(4, 4); pb_color_bar.BackColor = Color.FromArgb(255, 255, 255, 255); parent.Controls.Add(pb_color_bar); pb_bar = new PictureBox(); pb_bar.Width = width; pb_bar.Height = 1; pb_bar.Location = new Point(4, 4); pb_bar.BackColor = Color.FromArgb(100, 255, 255, 255); parent.Controls.Add(pb_bar); touch.MouseDown += new MouseEventHandler((o, e) => { bClick = true; }); touch.MouseUp += new MouseEventHandler((o, e) => { bClick = false; }); touch.MouseMove += new MouseEventHandler(SeekbarMoveEvent); void SeekbarMoveEvent(object o, MouseEventArgs e) { if (bClick) { SetValueByPoint(e.X); } } }