回答編集履歴

4

間違って DestroyCaret を消してしまった

2021/11/24 08:17

投稿

KOZ6.0
KOZ6.0

スコア2657

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  [DllImport("User32")]
46
46
 
47
- private static extern bool HideCaret(IntPtr hWnd);
47
+ private static extern bool DestroyCaret();
48
48
 
49
49
 
50
50
 

3

LostFocus 時の HideCaret は不要

2021/11/24 08:17

投稿

KOZ6.0
KOZ6.0

スコア2657

test CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  反転してたようです。(^_^;)
10
10
 
11
+
12
+
11
13
  ```C#
12
14
 
13
15
  using System;
@@ -42,12 +44,6 @@
42
44
 
43
45
  [DllImport("User32")]
44
46
 
45
- private static extern bool DestroyCaret();
46
-
47
-
48
-
49
- [DllImport("User32")]
50
-
51
47
  private static extern bool HideCaret(IntPtr hWnd);
52
48
 
53
49
 
@@ -74,8 +70,6 @@
74
70
 
75
71
  textBox1.GotFocus += TextBox1_GotFocus;
76
72
 
77
- textBox1.LostFocus += TextBox1_LostFocus;
78
-
79
73
  using (var bmp = new Bitmap(CaretWidth, textBox1.Font.Height))
80
74
 
81
75
  {
@@ -94,6 +88,8 @@
94
88
 
95
89
  }
96
90
 
91
+
92
+
97
93
  private static Color CreateCaretColor(Color color)
98
94
 
99
95
  {
@@ -136,16 +132,6 @@
136
132
 
137
133
  }
138
134
 
139
-
140
-
141
- private void TextBox1_LostFocus(object sender, EventArgs e)
142
-
143
- {
144
-
145
- HideCaret(textBox1.Handle);
146
-
147
- }
148
-
149
135
  }
150
136
 
151
137
  ```

2

反転してたようです。(^_^;)

2021/11/23 02:14

投稿

KOZ6.0
KOZ6.0

スコア2657

test CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  ただ、Color.Red のビットマップを作成して CreateCaret に渡しているのですが、なぜか水色で表示されちゃいます。
4
4
 
5
- 反転とかしてるんですかね。(^_^;)
5
+ ~~反転とかしてるんですかね。(^_^;)
6
+
6
-
7
+ ~~
8
+
7
-
9
+ 反転してたようです。(^_^;)
8
10
 
9
11
  ```C#
10
12
 
@@ -82,7 +84,7 @@
82
84
 
83
85
  {
84
86
 
85
- g.Clear(Color.Red);
87
+ g.Clear(CreateCaretColor(Color.Red));
86
88
 
87
89
  }
88
90
 
@@ -92,6 +94,22 @@
92
94
 
93
95
  }
94
96
 
97
+ private static Color CreateCaretColor(Color color)
98
+
99
+ {
100
+
101
+ int A = color.A;
102
+
103
+ int R = color.R ^ 0xff;
104
+
105
+ int G = color.G ^ 0xff;
106
+
107
+ int B = color.B ^ 0xff;
108
+
109
+ return Color.FromArgb(A, R, G, B);
110
+
111
+ }
112
+
95
113
 
96
114
 
97
115
  protected override void OnFormClosed(FormClosedEventArgs e)

1

不要なコードを削除

2021/11/21 14:18

投稿

KOZ6.0
KOZ6.0

スコア2657

test CHANGED
@@ -90,8 +90,6 @@
90
90
 
91
91
  }
92
92
 
93
- timer1.Start();
94
-
95
93
  }
96
94
 
97
95