回答編集履歴

1

見直しキャンペーン中

2023/07/27 16:18

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -1,79 +1,40 @@
1
1
  どうしてそういう状態になるんでしょうね?(根深そうなので特に深入りしませんが^^;
2
2
 
3
-
4
-
5
3
  そもそも余白のクリックを無視させるというアプローチがありました。
6
-
7
4
  [ListView Losing focus while clicking on blank space of listview in C#.net - CodeProject](https://www.codeproject.com/Questions/164806/ListView-Losing-focus-while-clicking-on-blank-spac)
8
5
 
9
-
10
-
11
6
  `ListView`を`MyListView`に入れ替えます。
12
-
13
7
  コードの詳細は分かっていませんが、希望の動きになっていると思います。
14
8
 
15
-
16
-
17
- ```C#
9
+ ```cs
18
-
19
10
  using System.Drawing;
20
-
21
11
  using System.Windows.Forms;
22
12
 
23
-
24
-
25
13
  namespace Questions346626
26
-
27
14
  {
28
-
29
15
  public partial class MyListView : ListView
30
-
31
16
  {
32
-
33
17
  public MyListView() => InitializeComponent();
34
18
 
35
-
36
-
37
19
  protected override void WndProc(ref Message msg)
38
-
39
20
  {
40
-
41
21
  // Ignore mouse messages not in the client area
42
-
43
22
  if (msg.Msg >= 0x201 && msg.Msg <= 0x209)
44
-
45
23
  {
46
-
47
24
  var pointMousePos = new Point(msg.LParam.ToInt32() & 0xffff, msg.LParam.ToInt32() >> 16);
48
-
49
25
  var lvhti = HitTest(pointMousePos);
50
-
51
26
  switch (lvhti.Location)
52
-
53
27
  {
54
-
55
28
  case ListViewHitTestLocations.AboveClientArea:
56
-
57
29
  case ListViewHitTestLocations.BelowClientArea:
58
-
59
30
  case ListViewHitTestLocations.LeftOfClientArea:
60
-
61
31
  case ListViewHitTestLocations.RightOfClientArea:
62
-
63
32
  case ListViewHitTestLocations.None:
64
-
65
33
  return;
66
-
67
34
  }
68
-
69
35
  }
70
-
71
36
  base.WndProc(ref msg);
72
-
73
37
  }
74
-
75
38
  }
76
-
77
39
  }
78
-
79
40
  ```