65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Windows.Forms;
|
|
|
|
internal class Slider : Ctl
|
|
{
|
|
public double Value;
|
|
|
|
public double Lo;
|
|
|
|
public double Hi;
|
|
|
|
public event Action Changed;
|
|
|
|
public Slider(double lo, double hi)
|
|
{
|
|
Lo = lo;
|
|
Hi = hi;
|
|
Size = new Size(320, 30);
|
|
}
|
|
|
|
private void Pick(int x)
|
|
{
|
|
double num = Lo + (Hi - Lo) * Math.Max(0.0, Math.Min(1.0, ((double)x - 8.0) / (double)(Width - 64)));
|
|
Value = Math.Round(num * 2.0) / 2.0;
|
|
Invalidate();
|
|
if (Changed != null)
|
|
{
|
|
Changed();
|
|
}
|
|
}
|
|
|
|
protected override void OnMouseDown(MouseEventArgs e)
|
|
{
|
|
Pick(e.X);
|
|
}
|
|
|
|
protected override void OnMouseMove(MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
Pick(e.X);
|
|
}
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
Graphics graphics = e.Graphics;
|
|
Prep(graphics);
|
|
graphics.Clear(BackColor);
|
|
float num = Width - 64;
|
|
float num2 = 8f + (float)((Value - Lo) / (Hi - Lo)) * num;
|
|
float num3 = (float)Height / 2f;
|
|
G.Fill(graphics, new RectangleF(8f, num3 - 2f, num, 4f), 2f, G.Line);
|
|
G.Fill(graphics, new RectangleF(8f, num3 - 2f, num2 - 8f, 4f), 2f, G.Acc);
|
|
using (SolidBrush brush = new SolidBrush(Color.White))
|
|
{
|
|
graphics.FillEllipse(brush, num2 - 7f, num3 - 7f, 14f, 14f);
|
|
}
|
|
G.Fill(graphics, new RectangleF(Width - 48, num3 - 12f, 48f, 24f), 8f, G.Bg);
|
|
G.T(graphics, Value.ToString("0.0", CultureInfo.InvariantCulture), G.S, G.Txt, Width - 24, num3 - 9f, StringAlignment.Center);
|
|
}
|
|
}
|