using System.IO; // for File, StreamReader using System.Text; // for Encoding public class MyForm : Form { private Button button1; private TextBox textBox1; private RichTextBox richTextBox1; |
public MyForm() { InitializeComponent(); button1.Hide(); textBox1.Hide(); string file_name = @"C:\DATA\CSForm.cs"; StreamReader reader = new StreamReader(file_name); string str; str = reader.ReadToEnd(); richTextBox1.Text = str; reader.Close(); } |
// richTextBox1 this.richTextBox1.Location = new System.Drawing.Point(12, 12); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(551, 409); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = ""; this.richTextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouse_Click); |
// richTextBox でマウスがクリックされたとき private void mouse_Click(object sender, MouseEventArgs e) { // MessageBox.Show("マウスがクリックされた"); richTextBox1.Hide(); button1.Show(); textBox1.Show(); } |
// ボタンクリックでキーサーチ private void button_Click(object sender, EventArgs e) { string s_key; s_key = textBox1.Text; for(int pos = 0; ; ) { pos = richTextBox1.Find(s_key, pos, RichTextBoxFinds.None); if (pos < 0) break; richTextBox1.SelectionColor = Color.DarkMagenta; pos++; } richTextBox1.Select(0, 0); richTextBox1.Show(); button1.Hide(); textBox1.Hide(); } |
this.richTextBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_DoubleClick); //this.richTextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouse_Click); |
private void richTextBox1_DoubleClick(object sender, MouseEventArgs e) { MessageBox.Show("RichTextBox DoubleClick"); int pos = richTextBox1.SelectionStart; richTextBox1.Select(pos, 8); this.Text = richTextBox1.SelectedText; } |