回答編集履歴

1

見直しキャンペーン中

2023/07/22 10:04

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -1,113 +1,57 @@
1
1
  古い行の削除にも需要はあると思いますので回答しておきます。
2
2
 
3
-
4
-
5
3
  [c# - Delete a specific line in a .NET RichTextBox - Stack Overflow](https://stackoverflow.com/questions/1329347/delete-a-specific-line-in-a-net-richtextbox/20983817#20983817)
6
-
7
4
  で、書式を維持したままの行削除を確認できました。
8
5
 
9
-
10
-
11
- ```C#
6
+ ```cs
12
-
13
7
  using System;
14
-
15
8
  using System.Drawing;
16
-
17
9
  using System.Linq;
18
-
19
10
  using System.Windows.Forms;
20
11
 
21
-
22
-
23
12
  namespace Questions281426
24
-
25
13
  {
26
-
27
14
  public partial class Form1 : Form
28
-
29
15
  {
30
-
31
16
  private Timer timer1;
32
-
33
17
  private RichTextBox richTextBox1;
34
-
35
18
  private int c;
36
19
 
37
-
38
-
39
20
  public Form1()
40
-
41
21
  {
42
-
43
22
  InitializeComponent();
44
23
 
45
-
46
-
47
24
  timer1 = new Timer
48
-
49
25
  {
50
-
51
26
  Enabled = true,
52
-
53
27
  Interval = 1000,
54
-
55
28
  };
56
-
57
29
  timer1.Tick += Timer1_Tick;
58
30
 
59
-
60
-
61
31
  richTextBox1 = new RichTextBox
62
-
63
32
  {
64
-
65
33
  Dock = DockStyle.Fill,
66
-
67
34
  };
68
-
69
35
  Controls.Add(richTextBox1);
70
-
71
36
  }
72
37
 
73
-
74
-
75
38
  private void Timer1_Tick(object sender, EventArgs e)
76
-
77
39
  {
78
-
79
40
  // なんか追加
80
-
81
41
  richTextBox1.SelectionStart = richTextBox1.TextLength;
82
-
83
42
  richTextBox1.SelectionLength = 0;
84
-
85
43
  richTextBox1.SelectionColor = ++c % 2 == 0 ? Color.Red : Color.Blue;
86
-
87
44
  richTextBox1.AppendText($"あああああ{c}\n");
88
45
 
89
-
90
-
91
46
  // 10行以上あったら先頭から削除
92
-
93
47
  while(10 < richTextBox1.Lines.Count())
94
-
95
48
  {
96
-
97
49
  //[c# - Delete a specific line in a .NET RichTextBox - Stack Overflow](https://stackoverflow.com/questions/1329347/delete-a-specific-line-in-a-net-richtextbox/20983817#20983817)
98
-
99
50
  richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(0);
100
-
101
51
  richTextBox1.SelectionLength = richTextBox1.Lines[0].Length + 1;
102
-
103
52
  richTextBox1.SelectedText = string.Empty;
104
-
105
53
  }
106
-
107
54
  }
108
-
109
55
  }
110
-
111
56
  }
112
-
113
57
  ```