File: ToolstripNumericUpDown.cs

package info (click to toggle)
quickroute-gps 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,576 kB
  • sloc: cs: 74,488; makefile: 72; sh: 43
file content (84 lines) | stat: -rw-r--r-- 2,488 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.Design;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

namespace QuickRoute.Controls
{
  [DesignerCategory("code")]
  [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
  public class ToolstripNumericUpDown : ToolStripControlHost
  {
    public ToolstripNumericUpDown()
      : base(CreateControlInstance())
    {
      this.Enter += new EventHandler(ToolstripNumericUpDown_Enter);
    }

    void ToolstripNumericUpDown_Enter(object sender, EventArgs e)
    {
      NumericUpDownControl.Select(0, NumericUpDownControl.Text.Length);
      NumericUpDownControl.Focus();
    }

    /// <summary>
    /// Export a strongly typed property called colorRangeIntervalSlider - handy to prevent casting everywhere.
    /// </summary>
    public NumericUpDown NumericUpDownControl
    {
      get
      {
        return Control as NumericUpDown;
      }
    }

    private static Control CreateControlInstance()
    {
      NumericUpDown nud = new NumericUpDown();
      nud.AutoSize = false;
      nud.Size = new Size(40, 24);
      // Add other initialization code here.
      return nud;
    }

    /// <summary>
    /// Attach to events we want to re-wrap
    /// </summary>
    /// <param name="control"></param>
    protected override void OnSubscribeControlEvents(Control control)
    {
      base.OnSubscribeControlEvents(control);
      NumericUpDownControl.ValueChanged += new System.EventHandler(NumericUpDownControl_ValueChanged);
    }
    /// <summary>
    /// Detach from events.
    /// </summary>
    /// <param name="control"></param>
    protected override void OnUnsubscribeControlEvents(Control control)
    {
      base.OnUnsubscribeControlEvents(control);
      NumericUpDownControl.ValueChanged -= new System.EventHandler(NumericUpDownControl_ValueChanged);
    }

    void NumericUpDownControl_ValueChanged(object sender, EventArgs e)
    {
      if (this.ValueChanged != null) this.ValueChanged(sender, e);
    }
    // add events that are subscribable from the designer.
    public event EventHandler ValueChanged;

    // set other defaults that are interesting
    protected override Size DefaultSize
    {
      get
      {
        return new Size(40, 24);
      }
    }

  }

}