文本框制作
阿新 • • 發佈:2017-05-17
too pub tdi 替換 dex sha for ring box
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }//時間按鈕點擊事件 private void 時間日期ToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Text = DateTime.Now.ToString("HH:mm yyyy/MM/dd"); } //撤銷按鈕點擊事件 private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Undo(); }//剪切按鈕事件 private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Cut(); } //復制按鈕事件 private void 復制CToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Copy(); } //粘貼按鈕事件 privatevoid 粘貼PToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Paste(); } //刪除按鈕事件 private void toolStripMenuItem3_Click(object sender, EventArgs e) { textBox1.SelectedText = ""; } //全選按鈕事件 private void 全選AToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.SelectAll(); } //查找按鈕事件 private void toolStripMenuItem1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(this); f2.Owner = this; f2.Show(); } //替換按鈕點擊事件 private void 替換ToolStripMenuItem_Click(object sender, EventArgs e) { Form3 f3 = new Form3(this); f3.Owner = this; f3.Show(); } //換行按鈕點擊事件 private void 自動換行ToolStripMenuItem_Click(object sender, EventArgs e) { if (textBox1.WordWrap) { textBox1.WordWrap = false; textBox1.ScrollBars = ScrollBars.Both; } else { textBox1.WordWrap = true; textBox1.ScrollBars = ScrollBars.Vertical; } } //字體按鈕點擊事件 private void 字體ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dll = fontDialog1.ShowDialog(); if (dll == DialogResult.OK) { textBox1.Font = fontDialog1.Font; } } //顏色按鈕點擊事件 private void 字體ToolStripMenuItem1_Click(object sender, EventArgs e) { DialogResult dll = colorDialog1.ShowDialog(); if (dll == DialogResult.OK) { textBox1.ForeColor = colorDialog1.Color; } } //打開按鈕點擊事件 private void 打開OToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "文本文件|*.txt";//選擇文件能打開格式,多個"文本文件|*.txt|文本文檔|*.doc|所有文件|*.*" DialogResult dll = openFileDialog1.ShowDialog(); if (dll == DialogResult.OK) { //打開文件路徑,以文件的默認編碼方式打開 StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default); textBox1.Text = sr.ReadToEnd(); } } string save = ""; private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) { if (save == "")//判斷有沒有保存路徑 { DialogResult dll = saveFileDialog1.ShowDialog(); if (dll == DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.Write(textBox1.Text); sw.Flush(); save = saveFileDialog1.FileName; sw.Close(); } } else { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.Write(textBox1.Text); sw.Flush(); sw.Close(); } } //底部菜單欄 private void textBox1_TextChanged(object sender, EventArgs e) { toolStripLabel1.Text = "字數:" + textBox1.TextLength; toolStripLabel2.Text = "行數" + (textBox1.GetLineFromCharIndex(textBox1.TextLength)+1); } } } form1
Form1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form2 : Form { Form1 F1 = null; public Form2(Form1 f1) { InitializeComponent(); F1 = f1; } int z = 0; private void button1_Click(object sender, EventArgs e) { string s = F1.textBox1.Text; if (z < 0) { z = 0; } z = s.IndexOf(textBox1.Text, z); if (z >= 0) { F1.textBox1.Select(z, textBox1.TextLength); F1.Focus(); z++; } else { MessageBox.Show("找不到" + "\"" + textBox1.Text + "\""); } } } } form2
Form2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form3 : Form { Form1 F1 = null; public Form3(Form1 f1) { InitializeComponent(); F1 = f1; } private void button1_Click(object sender, EventArgs e) { int z = 0; string s = F1.textBox1.Text; if (s.IndexOf(textBox1.Text, z) < 0) { MessageBox.Show("找不到" + "\"" + textBox1.Text + "\""); } for (; ; ) { if (z < 0) { F1.Focus(); break; } z = s.IndexOf(textBox1.Text, z); if (z >= 0) { F1.textBox1.Select(z, textBox1.TextLength); F1.textBox1.SelectedText = textBox2.Text; z++; } } } } } form3
Form3
文本框制作