204 lines
4.6 KiB
C#
204 lines
4.6 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace VideoReader;
|
|
|
|
[Description("Very basic slider control with selection range.")]
|
|
public class SelectionRangeSlider : UserControl
|
|
{
|
|
private enum MovingMode
|
|
{
|
|
MovingValue,
|
|
MovingMin,
|
|
MovingMax
|
|
}
|
|
|
|
private int min = 0;
|
|
|
|
private int max = 100;
|
|
|
|
private int selectedMin = 0;
|
|
|
|
private int selectedMax = 100;
|
|
|
|
private int value = 50;
|
|
|
|
private MovingMode movingMode;
|
|
|
|
private IContainer components = null;
|
|
|
|
[Description("Minimum value of the slider.")]
|
|
public int Min
|
|
{
|
|
get
|
|
{
|
|
return min;
|
|
}
|
|
set
|
|
{
|
|
min = value;
|
|
((Control)this).Invalidate();
|
|
}
|
|
}
|
|
|
|
[Description("Maximum value of the slider.")]
|
|
public int Max
|
|
{
|
|
get
|
|
{
|
|
return max;
|
|
}
|
|
set
|
|
{
|
|
max = value;
|
|
((Control)this).Invalidate();
|
|
}
|
|
}
|
|
|
|
[Description("Minimum value of the selection range.")]
|
|
public int SelectedMin
|
|
{
|
|
get
|
|
{
|
|
return selectedMin;
|
|
}
|
|
set
|
|
{
|
|
selectedMin = value;
|
|
if (this.SelectionChanged != null)
|
|
{
|
|
this.SelectionChanged(this, null);
|
|
}
|
|
((Control)this).Invalidate();
|
|
}
|
|
}
|
|
|
|
[Description("Maximum value of the selection range.")]
|
|
public int SelectedMax
|
|
{
|
|
get
|
|
{
|
|
return selectedMax;
|
|
}
|
|
set
|
|
{
|
|
selectedMax = value;
|
|
if (this.SelectionChanged != null)
|
|
{
|
|
this.SelectionChanged(this, null);
|
|
}
|
|
((Control)this).Invalidate();
|
|
}
|
|
}
|
|
|
|
[Description("Current value.")]
|
|
public int Value
|
|
{
|
|
get
|
|
{
|
|
return value;
|
|
}
|
|
set
|
|
{
|
|
this.value = value;
|
|
if (this.ValueChanged != null)
|
|
{
|
|
this.ValueChanged(this, null);
|
|
}
|
|
((Control)this).Invalidate();
|
|
}
|
|
}
|
|
|
|
[Description("Fired when SelectedMin or SelectedMax changes.")]
|
|
public event EventHandler SelectionChanged;
|
|
|
|
[Description("Fired when Value changes.")]
|
|
public event EventHandler ValueChanged;
|
|
|
|
public SelectionRangeSlider()
|
|
{
|
|
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0068: Expected O, but got Unknown
|
|
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007b: Expected O, but got Unknown
|
|
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008e: Expected O, but got Unknown
|
|
InitializeComponent();
|
|
((Control)this).SetStyle((ControlStyles)8192, true);
|
|
((Control)this).SetStyle((ControlStyles)131072, true);
|
|
((Control)this).Paint += new PaintEventHandler(SelectionRangeSlider_Paint);
|
|
((Control)this).MouseDown += new MouseEventHandler(SelectionRangeSlider_MouseDown);
|
|
((Control)this).MouseMove += new MouseEventHandler(SelectionRangeSlider_MouseMove);
|
|
}
|
|
|
|
private void SelectionRangeSlider_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
e.Graphics.FillRectangle(Brushes.White, ((Control)this).ClientRectangle);
|
|
Rectangle rectangle = new Rectangle((selectedMin - Min) * ((Control)this).Width / (Max - Min), 0, (selectedMax - selectedMin) * ((Control)this).Width / (Max - Min), ((Control)this).Height);
|
|
e.Graphics.FillRectangle(Brushes.Blue, rectangle);
|
|
e.Graphics.DrawRectangle(Pens.Black, 0, 0, ((Control)this).Width - 1, ((Control)this).Height - 1);
|
|
e.Graphics.DrawLine(Pens.Black, (Value - Min) * ((Control)this).Width / (Max - Min), 0, (Value - Min) * ((Control)this).Width / (Max - Min), ((Control)this).Height);
|
|
}
|
|
|
|
private void SelectionRangeSlider_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
int num = Min + e.X * (Max - Min) / ((Control)this).Width;
|
|
int num2 = Math.Abs(num - Value);
|
|
int num3 = Math.Abs(num - SelectedMin);
|
|
int val = Math.Abs(num - SelectedMax);
|
|
int num4 = Math.Min(num2, Math.Min(num3, val));
|
|
if (num4 == num2)
|
|
{
|
|
movingMode = MovingMode.MovingValue;
|
|
}
|
|
else if (num4 == num3)
|
|
{
|
|
movingMode = MovingMode.MovingMin;
|
|
}
|
|
else
|
|
{
|
|
movingMode = MovingMode.MovingMax;
|
|
}
|
|
SelectionRangeSlider_MouseMove(sender, e);
|
|
}
|
|
|
|
private void SelectionRangeSlider_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Invalid comparison between Unknown and I4
|
|
if ((int)e.Button == 1048576)
|
|
{
|
|
int num = Min + e.X * (Max - Min) / ((Control)this).Width;
|
|
if (movingMode == MovingMode.MovingValue)
|
|
{
|
|
Value = num;
|
|
}
|
|
else if (movingMode == MovingMode.MovingMin)
|
|
{
|
|
SelectedMin = num;
|
|
}
|
|
else if (movingMode == MovingMode.MovingMax)
|
|
{
|
|
SelectedMax = num;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing && components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
((ContainerControl)this).Dispose(disposing);
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
components = new Container();
|
|
((ContainerControl)this).AutoScaleMode = (AutoScaleMode)1;
|
|
}
|
|
}
|