-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormOutput.cs
392 lines (371 loc) · 14.1 KB
/
FormOutput.cs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;
namespace PlotReader
{
/// <summary>
/// Summary description for FormOutput.
/// </summary>
public class FormOutput : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboCulture;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioDefault;
private System.Windows.Forms.RadioButton radioEnglish;
private System.Windows.Forms.RadioButton radioOther;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton radioScientific;
private System.Windows.Forms.RadioButton radioFixedPoint;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboSeparator;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericDecimals;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private string m_strRegKey = null;
public FormOutput(string strRegKey)
{
InitializeComponent();
// Fill combo box with names of all available formatting cultures.
CultureInfo [] cults = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
this.comboCulture.DisplayMember = "EnglishName";
this.comboCulture.Items.AddRange(cults);
this.comboCulture.SelectedIndex = 0;
// Select first separator by default.
this.comboSeparator.SelectedIndex = 0;
Microsoft.Win32.RegistryKey regSettingsRoot = null;
if (strRegKey != null) regSettingsRoot = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strRegKey,false);
if (regSettingsRoot != null)
{
// NumberStyle=0: scientific, NumberStyle=1: fixed-point
int iStyle = (int)regSettingsRoot.GetValue("NumberStyle",(int)0);
if (iStyle==1) this.radioFixedPoint.Checked = true;
// NumberCulture=0: user default, NumberCulture=1: US English, NumberCulture=2: custom.
int iCultureType = (int)regSettingsRoot.GetValue("NumberCulture",(int)0);
switch (iCultureType)
{
case (0):
this.radioDefault.Checked = true;
break;
case (1):
this.radioEnglish.Checked = true;
break;
case (2):
this.radioOther.Checked = true;
break;
}
// CustomCulture stored as CultureInfo name, e.g. "en-US".
string strCustomCulture = (string)regSettingsRoot.GetValue("CustomCulture",cults[0].Name);
int iCurrent = 0;
foreach (CultureInfo ci in this.comboCulture.Items)
{
if (ci.Name==strCustomCulture) this.comboCulture.SelectedIndex = iCurrent;
iCurrent++;
}
this.numericDecimals.Value = (int)regSettingsRoot.GetValue("NumberOfDecimals",(int)this.numericDecimals.Value);
this.comboSeparator.Text = (string)regSettingsRoot.GetValue("Separator",this.comboSeparator.Text);
}
this.m_strRegKey = strRegKey;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
Microsoft.Win32.RegistryKey regSettingsRoot = null;
if (this.m_strRegKey != null) regSettingsRoot = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(this.m_strRegKey,true);
if (regSettingsRoot != null)
{
int iStyle = (this.radioFixedPoint.Checked ? 1 : 0);
regSettingsRoot.SetValue("NumberStyle",iStyle);
if (this.radioDefault.Checked)
regSettingsRoot.SetValue("NumberCulture",(int)0);
else if (this.radioEnglish.Checked)
regSettingsRoot.SetValue("NumberCulture",(int)1);
else if (this.radioOther.Checked)
{
regSettingsRoot.SetValue("NumberCulture",(int)2);
regSettingsRoot.SetValue("CustomCulture",((CultureInfo)this.comboCulture.SelectedItem).Name);
}
regSettingsRoot.SetValue("NumberOfDecimals",(int)this.numericDecimals.Value);
regSettingsRoot.SetValue("Separator",this.comboSeparator.Text);
}
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormOutput));
this.comboCulture = new System.Windows.Forms.ComboBox();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioDefault = new System.Windows.Forms.RadioButton();
this.radioEnglish = new System.Windows.Forms.RadioButton();
this.radioOther = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.radioScientific = new System.Windows.Forms.RadioButton();
this.radioFixedPoint = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.comboSeparator = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.numericDecimals = new System.Windows.Forms.NumericUpDown();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericDecimals)).BeginInit();
this.SuspendLayout();
//
// comboCulture
//
this.comboCulture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboCulture.Enabled = false;
this.comboCulture.Location = new System.Drawing.Point(64, 66);
this.comboCulture.Name = "comboCulture";
this.comboCulture.Size = new System.Drawing.Size(192, 21);
this.comboCulture.Sorted = true;
this.comboCulture.TabIndex = 1;
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.buttonOK.Location = new System.Drawing.Point(112, 248);
this.buttonOK.Name = "buttonOK";
this.buttonOK.TabIndex = 2;
this.buttonOK.Text = "OK";
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.buttonCancel.Location = new System.Drawing.Point(200, 248);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Cancel";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.radioDefault);
this.groupBox1.Controls.Add(this.comboCulture);
this.groupBox1.Controls.Add(this.radioEnglish);
this.groupBox1.Controls.Add(this.radioOther);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Location = new System.Drawing.Point(8, 88);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(264, 96);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Number formatting culture";
//
// radioDefault
//
this.radioDefault.Checked = true;
this.radioDefault.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.radioDefault.Location = new System.Drawing.Point(8, 16);
this.radioDefault.Name = "radioDefault";
this.radioDefault.Size = new System.Drawing.Size(248, 24);
this.radioDefault.TabIndex = 2;
this.radioDefault.TabStop = true;
this.radioDefault.Text = "User default (configured in control panel)";
//
// radioEnglish
//
this.radioEnglish.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.radioEnglish.Location = new System.Drawing.Point(8, 40);
this.radioEnglish.Name = "radioEnglish";
this.radioEnglish.Size = new System.Drawing.Size(248, 24);
this.radioEnglish.TabIndex = 2;
this.radioEnglish.Text = "English (United States)";
//
// radioOther
//
this.radioOther.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.radioOther.Location = new System.Drawing.Point(8, 64);
this.radioOther.Name = "radioOther";
this.radioOther.Size = new System.Drawing.Size(64, 24);
this.radioOther.TabIndex = 2;
this.radioOther.Text = "Other:";
this.radioOther.CheckedChanged += new System.EventHandler(this.radioOther_CheckedChanged);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.radioScientific);
this.groupBox2.Controls.Add(this.radioFixedPoint);
this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox2.Location = new System.Drawing.Point(8, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(264, 72);
this.groupBox2.TabIndex = 4;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Number style";
//
// radioScientific
//
this.radioScientific.Checked = true;
this.radioScientific.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.radioScientific.Location = new System.Drawing.Point(8, 16);
this.radioScientific.Name = "radioScientific";
this.radioScientific.Size = new System.Drawing.Size(248, 24);
this.radioScientific.TabIndex = 0;
this.radioScientific.TabStop = true;
this.radioScientific.Text = "Scientific (1.2134123e+001)";
//
// radioFixedPoint
//
this.radioFixedPoint.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.radioFixedPoint.Location = new System.Drawing.Point(8, 40);
this.radioFixedPoint.Name = "radioFixedPoint";
this.radioFixedPoint.Size = new System.Drawing.Size(248, 24);
this.radioFixedPoint.TabIndex = 0;
this.radioFixedPoint.Text = "Fixed-point (12.134123)";
//
// label1
//
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label1.Location = new System.Drawing.Point(8, 218);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 16);
this.label1.TabIndex = 5;
this.label1.Text = "Number separator:";
//
// comboSeparator
//
this.comboSeparator.Items.AddRange(new object[] {
"tab",
"semi-colon",
"comma",
"space"});
this.comboSeparator.Location = new System.Drawing.Point(112, 216);
this.comboSeparator.Name = "comboSeparator";
this.comboSeparator.Size = new System.Drawing.Size(88, 21);
this.comboSeparator.TabIndex = 6;
//
// label2
//
this.label2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label2.Location = new System.Drawing.Point(8, 194);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 16);
this.label2.TabIndex = 5;
this.label2.Text = "Number of decimals:";
//
// numericDecimals
//
this.numericDecimals.Location = new System.Drawing.Point(112, 192);
this.numericDecimals.Maximum = new System.Decimal(new int[] {
16,
0,
0,
0});
this.numericDecimals.Name = "numericDecimals";
this.numericDecimals.Size = new System.Drawing.Size(40, 20);
this.numericDecimals.TabIndex = 7;
this.numericDecimals.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.numericDecimals.Value = new System.Decimal(new int[] {
8,
0,
0,
0});
//
// FormOutput
//
this.AcceptButton = this.buttonOK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(282, 280);
this.Controls.Add(this.numericDecimals);
this.Controls.Add(this.comboSeparator);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.label2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormOutput";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Text output settings";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericDecimals)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void radioOther_CheckedChanged(object sender, System.EventArgs e)
{
this.comboCulture.Enabled = (this.radioOther.Checked);
}
public NumberFormatInfo Culture
{
get
{
if (this.radioDefault.Checked)
return NumberFormatInfo.CurrentInfo;
else if (this.radioEnglish.Checked)
return new CultureInfo("en-US", false).NumberFormat;
else
return ((CultureInfo)(this.comboCulture.SelectedItem)).NumberFormat;
}
}
public string Format
{
get
{
string strFormat;
// Get the number style.
if (this.radioFixedPoint.Checked)
strFormat = "f";
else
strFormat = "e";
// Get the number of decimals
strFormat += this.numericDecimals.Value;
return strFormat;
}
}
public string Separator
{
get
{
switch (this.comboSeparator.Text)
{
case "tab":
return "\t";
case "semi-colon":
return ";";
case "comma":
return ",";
case "space":
return " ";
default:
return this.comboSeparator.Text;
}
}
}
}
}