回答編集履歴

2

変更

2018/05/09 14:31

投稿

YAmaGNZ
YAmaGNZ

スコア10222

test CHANGED
@@ -222,15 +222,11 @@
222
222
 
223
223
  ```C#
224
224
 
225
- public static class UnsafeNativeMethods
225
+
226
-
227
- {
226
+
228
-
229
- [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
227
+ [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
230
-
228
+
231
- public static extern bool SetForegroundWindow(HandleRef hWnd);
229
+ public static extern bool SetForegroundWindow(HandleRef hWnd);
232
-
233
- }
234
230
 
235
231
 
236
232
 
@@ -238,7 +234,7 @@
238
234
 
239
235
  {
240
236
 
241
- UnsafeNativeMethods.SetForegroundWindow(new HandleRef(rmenu, rmenu.Handle));
237
+ SetForegroundWindow(new HandleRef(rmenu, rmenu.Handle));
242
238
 
243
239
  rmenu.Items.Clear();
244
240
 

1

追記

2018/05/09 14:31

投稿

YAmaGNZ
YAmaGNZ

スコア10222

test CHANGED
@@ -215,3 +215,49 @@
215
215
 
216
216
 
217
217
  多分もっとすっきりした方法があるのだと思います。
218
+
219
+
220
+
221
+ ### 追記
222
+
223
+ ```C#
224
+
225
+ public static class UnsafeNativeMethods
226
+
227
+ {
228
+
229
+ [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
230
+
231
+ public static extern bool SetForegroundWindow(HandleRef hWnd);
232
+
233
+ }
234
+
235
+
236
+
237
+ public static void OpenMenu()
238
+
239
+ {
240
+
241
+ UnsafeNativeMethods.SetForegroundWindow(new HandleRef(rmenu, rmenu.Handle));
242
+
243
+ rmenu.Items.Clear();
244
+
245
+ rmenu.Items.Add("アイテム1");
246
+
247
+ rmenu.Items.Add("アイテム2");
248
+
249
+ rmenu.Items.Add("-");
250
+
251
+ rmenu.Items.Add("キャンセル");
252
+
253
+ rmenu.Show(Cursor.Position, ToolStripDropDownDirection.BelowRight);
254
+
255
+ rmenu.ShowImageMargin = false;
256
+
257
+ }
258
+
259
+
260
+
261
+ ```
262
+
263
+ こうすることにより、フォームを表示し、フォーカス移動を行わなくてもタスクバーに表示されなくなりました。