More Related Content
Similar to Main Form Number To Word
Similar to Main Form Number To Word (14)
Main Form Number To Word
- 1. G:My DocumentsMy WorksDMNumberToWordNumberToWordMainForm.cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace NumberToWord
10 {
11 public partial class MainForm : Form
12 {
13 public MainForm()
14 {
15 InitializeComponent();
16 }
17
18 private void button1_Click(object sender, EventArgs e)
19 {
20 ConvertToWord con = new ConvertToWord();
21 //label1.Text = con.Convert(textBox1.Text);
22 richTextBox1.Text = con.Convert(textBox1.Text);
23 }
24 }
25
26
27 public class ConvertToWord
28 {
29 string word = "";
30 int index, j;
31
32 public string Convert(string value)
33 {
34 char[] number = value.ToCharArray();
35 index = value.Length;
36 j = 0;
37 for (int i = index; i > 0; i--)
38 {
39
40 word += CharToWord(number[j], i, j);
41 word += DigidToWord(number[j], i);
42
43
44 j++;
45 }
46
47
48
49 return word;
50
51 }
52
53 string CharToWord(char value, int digit, int first)
54 {
55 string wordChar = "";
56 switch (value)
57 {
58 case '1':
59 if ((digit % 6) == 1)
60 {
61 if (first == 0)
62 wordChar = " ";
63 else
64 wordChar = " ";
65 }
66 else if ((digit % 6) == 2)
67 wordChar = "";
68 else
69 wordChar = " ";
70 break;
71 case '2':
72 if ((digit % 6) == 2)
73 wordChar = " ";
74 else
- 2. G:My DocumentsMy WorksDMNumberToWordNumberToWordMainForm.cs 2
75 wordChar = " ";
76 break;
77 case '3':
78 wordChar = " ";
79 break;
80 case '4':
81 wordChar = " ";
82 break;
83 case '5':
84 wordChar = " ";
85 break;
86 case '6':
87 wordChar = " ก";
88 break;
89 case '7':
90 wordChar = " ";
91 break;
92 case '8':
93 wordChar = " ";
94 break;
95 case '9':
96 wordChar = " ก ";
97 break;
98
99 }
100 return wordChar;
101 }
102
103 string DigidToWord(char value, int digit)
104 {
105 string wordDigit = "";
106 if (digit != 1)
107 {
108 switch (digit % 6)
109 {
110 case 1:
111 wordDigit = " ";
112 break;
113 case 2:
114 if (value == '0')
115 wordDigit = "";
116 else
117 wordDigit = " ";
118 break;
119 case 3:
120 if (value == '0')
121 wordDigit = "";
122 else
123 wordDigit = " ";
124 break;
125 case 4:
126 if (value == '0')
127 wordDigit = "";
128 else
129 wordDigit = " ";
130 break;
131 case 5:
132 if (value == '0')
133 wordDigit = "";
134 else
135 wordDigit = " ";
136 break;
137 case 0:
138 if (value == '0')
139 wordDigit = "";
140 else
141 wordDigit = " ";
142 break;
143 }
144 }
145
146
147 return wordDigit;
148 }