標籤:namespace 檔案 成功 textbox down names model 不能 string
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//編輯框1內容變動產生觸發事件 功能區
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
textBox1.Text = "";
textBox2.Focus();
label5.Text = "請先輸入編碼長度";
label5.Visible = true;
}
else
{
textBox2.Enabled = false;
label5.Text = "雙擊編碼長度字樣可解鎖編輯";
label5.Visible = true;
textBox1.MaxLength = Convert.ToInt32(textBox2.Text);
if (textBox1.MaxLength == textBox1.Text.Length)
{
String text = textBox1.Text;
int indexToText = richTextBox1.Find(text,RichTextBoxFinds.MatchCase);
if (indexToText >= 0)
{
textBox1.Text = "";
textBox1.Focus();
}
else
{
//+ System.Environment.NewLine 此命令可以為richtextbox.text內容進行自動換行
richTextBox1.AppendText(textBox1.Text + System.Environment.NewLine);
textBox1.Text = "";
//下面兩行代碼實現richTextBox1.text內容與捲軸一起滾動
this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;
this.richTextBox1.ScrollToCaret();
}
}
}
}
//編碼長度標籤被雙擊事件 功能區
private void label2_DoubleClick(object sender, EventArgs e)
{
textBox2.Enabled = true;
}
//編輯框3斷行符號鍵按下事件功能區
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
String text = textBox3.Text;
int Text3 = richTextBox1.Find(text, RichTextBoxFinds.MatchCase);
if (Text3 >= 0)
{
label4.Text = "已掃描";
}
else
{
label4.Text = "此碼不存在";
textBox3.Text = "";
}
}
}
//組建檔案按鈕功能區
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.SaveFileDialog bcSave = new System.Windows.Forms.SaveFileDialog();
bcSave.Filter = "文字檔|*.txt|" + "WordPad檔案|*.rtf|" + "Word檔案|*.doc|" + "Excel檔案|*.xlsx|" + "所有檔案|*.*";
/* 此行按時間自動裝置檔案名稱
bcSave.FileName = "自訂檔案名稱" + DateTime.Now.ToString("yyyyMMddHHmm") + ".txt";
*/
if (bcSave.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(bcSave.FileName, RichTextBoxStreamType.PlainText);
MessageBox.Show("檔案已成功儲存");
}
}
//清除按鈕功能區
private void button2_Click(object sender, EventArgs e)
{
if (richTextBox1.Text != "")
{
richTextBox1.Text = "";
MessageBox.Show("記錄清除成功");
}
else
{
MessageBox.Show("快點工作吧,點來點去的");
}
}
}
}
C# 小白初入,請各位大神看看能不能最佳化下