using System; using System.Drawing; using System.Windows.Forms; internal class Seg : Ctl { public string[] Items; public int Index; private float pos; private Timer tm = new Timer(); public event Action Changed; public Seg(params string[] items) { Items = items; tm.Interval = 15; Timer timer = tm; EventHandler value = (object param0, EventArgs param1) => { pos += ((float)Index - pos) * 0.35f; if (Math.Abs((float)Index - pos) < 0.02f) { pos = Index; tm.Stop(); } Invalidate(); }; timer.Tick += value; } public void Set(int i) { Index = i; pos = i; Invalidate(); } protected override void OnMouseDown(MouseEventArgs e) { int num = Math.Min(Items.Length - 1, e.X * Items.Length / Width); if (num != Index) { Index = num; tm.Start(); if (Changed != null) { Changed(); } } } protected override void OnPaint(PaintEventArgs e) { Graphics graphics = e.Graphics; Prep(graphics); graphics.Clear(BackColor); float num = (float)Width / (float)Items.Length; G.Fill(graphics, new RectangleF(0f, 0f, Width - 1, Height - 1), 12f, G.Bg); G.Fill(graphics, new RectangleF(pos * num + 2f, 2f, num - 4f, Height - 5), 10f, G.Acc); for (int i = 0; i < Items.Length; i++) { G.T(graphics, Items[i], G.S, (i == Index) ? Color.FromArgb(10, 14, 28) : G.Dim, (float)i * num + num / 2f, Height / 2 - 9, StringAlignment.Center); } } }