回答編集履歴

1

追記

2016/07/13 02:32

投稿

Zuishin
Zuishin

スコア28656

test CHANGED
@@ -67,3 +67,69 @@
67
67
  }
68
68
 
69
69
  ```
70
+
71
+ ###追記
72
+
73
+ このような方法もあります。
74
+
75
+ ```C#
76
+
77
+ private KeyPressEventHandler keyPress;
78
+
79
+
80
+
81
+ private void EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
82
+
83
+ {
84
+
85
+ TextBox tb = (DataGridViewTextBoxEditingControl)e.Control;
86
+
87
+ //
88
+
89
+ //
90
+
91
+ // ここで生成したオブジェクトを、MyKeyPress内で利用したい
92
+
93
+ // このオブジェクトは列毎・画面毎に設定する内容が変わります。
94
+
95
+ Foo foo = new Foo();
96
+
97
+ foo.Length = 5;
98
+
99
+ foo.Scale = 3;
100
+
101
+
102
+
103
+ if (keyPress == null)
104
+
105
+ {
106
+
107
+ keyPress = createHandler(foo);
108
+
109
+ }
110
+
111
+ tb.KeyPress -= keyPress;
112
+
113
+ tb.KeyPress += keyPress;
114
+
115
+ }
116
+
117
+
118
+
119
+ public KeyPressEventHandler createHandler(Foo foo)
120
+
121
+ {
122
+
123
+ return (sender, e) =>
124
+
125
+ {
126
+
127
+ int len = foo.Length;
128
+
129
+ int scale = foo.Scale;
130
+
131
+ };
132
+
133
+ }
134
+
135
+ ```