Browse Subversion Repository
Contents of /SchoolIdolFestivalSimulator.Main/NumericTextBox.cs
Parent Directory
| Revision Log
Revision 41 -
( show annotations)
( download)
Fri Jun 6 12:57:06 2014 UTC
(9 years, 11 months ago)
by kayochin_3141
File size: 2044 byte(s)
自動入力→int.minvalue不具合
| 1 |
using System; |
| 2 |
using System.Collections.Generic; |
| 3 |
using System.Text; |
| 4 |
using System.Windows.Forms; |
| 5 |
using System.Security.Permissions; |
| 6 |
|
| 7 |
namespace SQLReport.Main { |
| 8 |
|
| 9 |
/// <summary> |
| 10 |
/// マウスやキーボードによるペーストを無効にしたTextBox |
| 11 |
/// </summary> |
| 12 |
public class NumericTextBox:TextBox { |
| 13 |
const int WM_PASTE = 0x302; |
| 14 |
const int ES_NUMBER = 0x2000; |
| 15 |
|
| 16 |
protected override void WndProc(ref Message m) { |
| 17 |
if (m.Msg == WM_PASTE) { |
| 18 |
return; |
| 19 |
} |
| 20 |
base.WndProc(ref m); |
| 21 |
} |
| 22 |
|
| 23 |
public decimal ValueDecimal { |
| 24 |
get { |
| 25 |
decimal ret = 0; |
| 26 |
if (decimal.TryParse(this.Text.Trim(), out ret)) { |
| 27 |
return ret; |
| 28 |
} |
| 29 |
return decimal.MinValue; |
| 30 |
} |
| 31 |
} |
| 32 |
public int Value { |
| 33 |
get { |
| 34 |
int ret = 0; |
| 35 |
if(int.TryParse(this.Text.Trim(), out ret)) { |
| 36 |
return ret; |
| 37 |
} |
| 38 |
return int.MinValue; |
| 39 |
} |
| 40 |
} |
| 41 |
protected override void OnKeyPress( |
| 42 |
System.Windows.Forms.KeyPressEventArgs e) { |
| 43 |
base.OnKeyPress(e); |
| 44 |
|
| 45 |
// 数字と小数点(1つ)以外入力させない |
| 46 |
if (e.KeyChar == '.') { |
| 47 |
if (this.Text.IndexOf(".") >= 0 || this.Text.Length == 0) { |
| 48 |
e.Handled = true; |
| 49 |
} |
| 50 |
} else if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b') { |
| 51 |
e.Handled = true; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
protected override CreateParams CreateParams { |
| 56 |
[SecurityPermission(SecurityAction.Demand, |
| 57 |
Flags = SecurityPermissionFlag.UnmanagedCode)] |
| 58 |
get { |
| 59 |
CreateParams parms = base.CreateParams; |
| 60 |
parms.Style |= ES_NUMBER; |
| 61 |
return parms; |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
|