Develop and Download Open Source Software

Browse Subversion Repository

Contents of /NeoFT/Controls/NonLinearUpDownControl.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download)
Tue Mar 25 12:06:05 2008 UTC (16 years ago) by c477
File size: 2178 byte(s)


1 using System;
2 using System.ComponentModel;
3 using System.Collections;
4 using System.Diagnostics;
5 using System.Windows.Forms;
6
7 namespace nft.controls
8 {
9 public enum NonLinearUpDownStyle { ZeroCorrectedLinearStep, GeometricStep, FirstDigitStep };
10
11 /// <summary>
12 /// NonLinierUpDownControl ‚ĚŠT—v‚Ěŕ–ž‚Ĺ‚ˇB
13 /// </summary>
14 public class NonLinearUpDownControl : NumericUpDown
15 {
16 public override void DownButton()
17 {
18 int d = (int)base.Value;
19 int i = (int)base.Increment;
20 switch(style)
21 {
22 case NonLinearUpDownStyle.ZeroCorrectedLinearStep:
23 {
24 int mod = d%i;
25 if(mod>0) d-=mod;
26 else d-=i;
27 break;
28 }
29 case NonLinearUpDownStyle.GeometricStep:
30 {
31 double e = Math.Log(d,i);
32 int n = (int)Math.Floor(e);
33 if(e==n) d /= i;
34 else d = (int)Math.Pow(i,n);
35 break;
36 }
37 case NonLinearUpDownStyle.FirstDigitStep:
38 {
39 double e = Math.Log10(d);
40 int n = (int)Math.Floor(e);
41 int b = (int)Math.Pow(10,n);
42 int mod = d%b;
43 if(mod>0)
44 d-=mod;
45 else if(d==b)
46 d-=b/10;
47 else
48 d-=b;
49 break;
50 }
51 }
52 base.Value = Math.Max(d,base.Minimum);
53 }
54 public override void UpButton()
55 {
56 int d = (int)base.Value;
57 int i = (int)base.Increment;
58 switch(style)
59 {
60 case NonLinearUpDownStyle.ZeroCorrectedLinearStep:
61 {
62 int mod = d%i;
63 if(mod>0) d+=i-mod;
64 else d+=i;
65 break;
66 }
67 case NonLinearUpDownStyle.GeometricStep:
68 {
69 double e = Math.Log(d,i);
70 int n = (int)Math.Floor(e);
71 if(e==n) d *= i;
72 else d = (int)Math.Pow(i,n+1);
73 break;
74 }
75 case NonLinearUpDownStyle.FirstDigitStep:
76 {
77 double e = Math.Log10(d);
78 int n = (int)Math.Floor(e);
79 int b = (int)Math.Pow(10,n);
80 int mod = d%b;
81 if(mod>0)
82 d+=i-mod;
83 else
84 d+=b;
85 break;
86 }
87 }
88 base.Value = Math.Min(d,base.Maximum);
89 }
90 protected NonLinearUpDownStyle style = NonLinearUpDownStyle.ZeroCorrectedLinearStep;
91 public NonLinearUpDownStyle Style
92 {
93 get{ return style; }
94 set{ style = value; }
95 }
96 }
97 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26