版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、(注:那個常用工具欄里的字體、字號、字符集不能用)主窗體里全部代碼: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;using System.Web;namespace NOTEBOOK public partial class Form1 : Form Find
2、 find = new Find(); replace replace = new replace(); public Form1() InitializeComponent(); find.Owner = this; replace.Owner = this; for (int i = 0; i <= System.Drawing.FontFamily.Families.Length - 1; i+) this.toolStripComboBox1.Items.Add(System.Drawing.FontFamily.Familiesi.Name); private void For
3、m1_Load(object sender, EventArgs e) /窗體加載 timer1.Enabled = true; DateTime now = DateTime.Now; time.Text = now.ToLongDateString() + now.ToLongTimeString(); private void timer1_Tick(object sender, EventArgs e) /控制時間 timer1.Enabled = true; DateTime now = DateTime.Now; time.Text = now.ToLongDateString()
4、 + now.ToLongTimeString(); / <summary> / 新建菜單 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) if (richTextBox1.Modified = true)/判斷當前文本是否處于編輯狀態(tài) DialogRes
5、ult r; r = MessageBox.Show("您是否將更改保存到 文檔 嗎?", "寫字板", MessageBoxButtons.YesNoCancel, MessageBoxIcon.None); if (r = DialogResult.Yes) 保存SToolStripMenuItem_Click(sender, e); richTextBox1.Clear(); this.Text = "新建-寫字板"/標題名稱 else if (r = DialogResult.No) richTextBox1.Clear();
6、 this.Text = "新建-寫字板" else richTextBox1.Clear(); this.Text = "新建-寫字板" richTextBox1.Modified = false; private void 打開OToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog 打開 = new OpenFileDialog(); 打開.Filter = "文本文件(*.txt)|*.txt|RTF文檔|*.rtf|所有文件|*.*" if (打開
7、.ShowDialog() = DialogResult.OK) string fn = 打開.FileName; string ext = Path.GetExtension(fn);/對應命名空間 this.Text = Path.GetFileNameWithoutExtension(fn) + "-記事本" if (ext.ToLower() = ".txt") richTextBox1.LoadFile(fn, RichTextBoxStreamType.PlainText); else if (ext.ToLower() = ".r
8、tf") richTextBox1.LoadFile(fn, RichTextBoxStreamType.RichText); else MessageBox.Show("系統(tǒng)不支持該類型文件!", "寫字板"); private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) SaveFileDialog saveFileDialog1 = new SaveFileDialog(); if (richTextBox1.Modified = true) saveFileDi
9、alog1.Title = "保存" saveFileDialog1.FileName = "*.txt"/默認文件名 saveFileDialog1.Filter = "文本文檔|*.txt|所有文檔|*.*" if (saveFileDialog1.ShowDialog() = DialogResult.OK) string fn = saveFileDialog1.FileName; richTextBox1.SaveFile(fn, RichTextBoxStreamType.RichText); richTextBox1.M
10、odified = false; this.Text = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + "-寫字板" else richTextBox1.SaveFile(this.Text, RichTextBoxStreamType.PlainText); richTextBox1.Modified = false; private void 另存為ToolStripMenuItem_Click(object sender, EventArgs e) SaveFileDialog saveFil
11、eDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "另存為" saveFileDialog1.FileName = "*.txt" saveFileDialog1.Filter = "文本文檔(*.txt)|*.txt|所有文檔|*.*" if (saveFileDialog1.ShowDialog() = DialogResult.OK) StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.W
12、rite(richTextBox1); richTextBox1.Modified = false; string fn = saveFileDialog1.FileName; sw.Close(); this.Text = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + "-寫字板" private void 打印PToolStripMenuItem_Click(object sender, EventArgs e) if (richTextBox1.Text.Length < 1) Mess
13、ageBox.Show("請確保要查找的文件的內(nèi)容不為空!", "提示"); return; else PrintDialog print = new PrintDialog(); DialogResult result = print.ShowDialog(); private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) if (richTextBox1.Text != "") 保存SToolStripMenuItem_Click(sender, e); e
14、lse this.Close(); / <summary> / 編輯菜單 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 編輯EToolStripMenuItem_Click(object sender, EventArgs e) /如果剪切板內(nèi)容不為空,則粘貼項不可用,否則不可用 string selectedInfo = "" if (Cl
15、ipboard.GetDataObject().GetDataPresent(DataFormats.Text) this.粘貼PToolStripMenuItem.Enabled = true; else this.粘貼PToolStripMenuItem.Enabled = false; /根據(jù)選擇區(qū)域不為空,則復制、剪切、刪除可用,否則不可用 if (richTextBox1.SelectedText.Equals("") && (selectedInfo.Equals("") 剪切TToolStripMenuItem.Enable
16、d = false; 復制CToolStripMenuItem.Enabled = false; 刪除DToolStripMenuItem.Enabled = false; else 剪切TToolStripMenuItem.Enabled = true; 復制CToolStripMenuItem.Enabled = true; 刪除DToolStripMenuItem.Enabled = true; /如果寫字板內(nèi)容不為空,則全選可用,否則不可用 if (richTextBox1.TextLength > 0) 全選AToolStripMenuItem1.Enabled = true;
17、 else 全選AToolStripMenuItem1.Enabled = false; private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e) richTextBox1.Undo(); 重做toolStripButton16.Enabled = true; private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e) if (richTextBox1.SelectionLength > 0) 剪切TToolStripMenuItem.
18、Enabled = true; richTextBox1.Cut(); private void 復制CToolStripMenuItem_Click(object sender, EventArgs e) richTextBox1.Copy(); private void 粘貼PToolStripMenuItem_Click(object sender, EventArgs e) richTextBox1.Paste(); private void 刪除DToolStripMenuItem1_Click(object sender, EventArgs e) if (richTextBox1
19、.SelectedText != "") int start = richTextBox1.SelectionStart; int len = richTextBox1.SelectionLength; richTextBox1.Text = richTextBox1.Text.Remove(start, len); richTextBox1.SelectionStart = start; private void 查找ToolStripMenuItem_Click(object sender, EventArgs e) find.Show(); private void
20、替換HToolStripMenuItem_Click(object sender, EventArgs e) replace.Show(); private void 全選AToolStripMenuItem1_Click(object sender, EventArgs e) richTextBox1.SelectAll(); private void 時間ToolStripMenuItem_Click(object sender, EventArgs e) /把時間、日期加到文本最后 richTextBox1.AppendText(DateTime.Now.ToString(); / &l
21、t;summary> / 查看菜單 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 工具欄TToolStripMenuItem_Click(object sender, EventArgs e) if (工具欄TToolStripMenuItem.Checked) 工具欄TToolStripMenuItem.Checked = false; 工具欄.Visible =
22、false; else 工具欄TToolStripMenuItem.Checked = true; 工具欄.Visible = true; private void 格式欄FToolStripMenuItem_Click(object sender, EventArgs e) if (格式欄FToolStripMenuItem.Checked) 格式欄FToolStripMenuItem.Checked = false; 格式欄.Visible = false; else 格式欄FToolStripMenuItem.Checked = true; 格式欄.Visible = true; pri
23、vate void 狀態(tài)欄SToolStripMenuItem_Click(object sender, EventArgs e) if (狀態(tài)欄SToolStripMenuItem.Checked) 狀態(tài)欄SToolStripMenuItem.Checked = false; 狀態(tài)欄.Visible = false; else 狀態(tài)欄SToolStripMenuItem.Checked = true; 狀態(tài)欄.Visible = true; / <summary> / 格式菜單 / </summary> / <param name="sender&qu
24、ot;></param> / <param name="e"></param> private void 自動換行ToolStripMenuItem_Click(object sender, EventArgs e) if (自動換行ToolStripMenuItem.Checked) 自動換行ToolStripMenuItem.Checked = false; richTextBox1.WordWrap = false; else 自動換行ToolStripMenuItem.Checked = true; richTextBox1
25、.WordWrap = true; private void 字體ToolStripMenuItem_Click(object sender, EventArgs e) 字體.Font = richTextBox1.Font; 字體.Color = richTextBox1.ForeColor; if (字體.ShowDialog() = DialogResult.OK) if (richTextBox1.SelectionLength > 0) richTextBox1.SelectionFont = 字體.Font; richTextBox1.SelectionColor = 字體.
26、Color; else richTextBox1.Font = 字體.Font; richTextBox1.ForeColor = 字體.Color; private void 顏色CToolStripMenuItem_Click(object sender, EventArgs e) 顏色.Color = richTextBox1.ForeColor; if (顏色.ShowDialog() = DialogResult.OK) if (richTextBox1.SelectionLength > 0) richTextBox1.SelectionColor = 顏色.Color; e
27、lse richTextBox1.ForeColor = 顏色.Color; / <summary> / 幫助菜單 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 關于寫字板ToolStripMenuItem_Click(object sender, EventArgs e) Help h = new Help(); h.ShowDialog(); / <s
28、ummary> / 工具欄按鈕 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 重做toolStripButton16_Click(object sender, EventArgs e) /重新應用上次撤消的操作 richTextBox1.Redo(); / <summary> / 格式欄按鈕 / </summary> / <param n
29、ame="sender"></param> / <param name="e"></param> private void toolStripComboBox1_Click(object sender, EventArgs e) /字體(未完成) private void toolStripComboBox2_Click(object sender, EventArgs e) /字號(未完成) private void toolStripComboBox3_Click(object sender, EventAr
30、gs e) /字體腳本(未完成) private void toolStripButton9_Click(object sender, EventArgs e) /加粗 Font oldfont = richTextBox1.SelectionFont; Font newfont; if (oldfont.Bold) newfont = new Font(oldfont, oldfont.Style & FontStyle.Bold); else newfont = new Font(oldfont, oldfont.Style | FontStyle.Bold); private v
31、oid toolStripButton10_Click(object sender, EventArgs e) /傾斜 Font oldfont = richTextBox1.SelectionFont; Font newfont; if (oldfont.Italic) newfont = new Font(oldfont, oldfont.Style & FontStyle.Italic); else newfont = new Font(oldfont, oldfont.Style | FontStyle.Italic); private void toolStripButton
32、11_Click(object sender, EventArgs e) /下劃線 Font oldfont = richTextBox1.SelectionFont; Font newfont; if (oldfont.Underline) newfont = new Font(oldfont, oldfont.Style & FontStyle.Underline); else newfont = new Font(oldfont, oldfont.Style | FontStyle.Underline); private void toolStripButton12_Click(
33、object sender, EventArgs e) /左對齊 richTextBox1.SelectionAlignment = HorizontalAlignment.Left; private void toolStripButton13_Click(object sender, EventArgs e) /居中 richTextBox1.SelectionAlignment = HorizontalAlignment.Center; private void toolStripButton14_Click(object sender, EventArgs e) /右對齊 richTe
34、xtBox1.SelectionAlignment = HorizontalAlignment.Right; / <summary> / 快捷菜單 / </summary> / <param name="sender"></param> / <param name="e"></param> private void 快捷菜單_Opening(object sender, CancelEventArgs e) /如果剪切板內(nèi)容不為空,則粘貼項可用,否則不可用 if (Clipboard
35、.GetDataObject().GetDataPresent(DataFormats.Text) this.剪切TToolStripMenuItem1.Enabled = true; else this.剪切TToolStripMenuItem1.Enabled = false; /根據(jù)選擇區(qū)域不為空,則復制、剪切、刪除可用,否則不可用 if (richTextBox1.SelectedText.Length > 0) 復制CToolStripMenuItem1.Enabled = true; 剪切TToolStripMenuItem1.Enabled = true; 刪除DToolS
36、tripMenuItem.Enabled = true; else 復制CToolStripMenuItem1.Enabled = false; 剪切TToolStripMenuItem1.Enabled = false; 刪除DToolStripMenuItem.Enabled = false; /如果寫字板內(nèi)容不為空,則全選可用,否則不可用 if (richTextBox1.Text.Length > 0) 全選AToolStripMenuItem1.Enabled = true; else 全選AToolStripMenuItem1.Enabled = false; / <s
37、ummary> / 窗體關閉按鈕 / </summary> / <param name="sender"></param> / <param name="e"></param> private void Form1_FormClosing(object sender, FormClosingEventArgs e) if (richTextBox1.Modified = true) DialogResult r; r = MessageBox.Show("您是不要將更改保存到 文
38、檔 嗎?", "寫字板", MessageBoxButtons.YesNoCancel, MessageBoxIcon.None); if (r = DialogResult.Yes) 保存SToolStripMenuItem_Click(sender, e); if (richTextBox1.Modified = true) e.Cancel = true; else e.Cancel = false; else if (r = DialogResult.Cancel) e.Cancel = true; else if (r = DialogResult.No
39、) e.Cancel = false; else e.Cancel = false; / <summary> / 在狀態(tài)欄顯示鼠標位置 / </summary> / <param name="sender"></param> / <param name="e"></param> private void richTextBox1_MouseMove(object sender, MouseEventArgs e) mouse.Text = "所在位置:" + e.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度銀行與旅游企業(yè)合作協(xié)議范本
- 二零二五年度隱名股東投資權益保障協(xié)議
- 二零二五年度零工經(jīng)濟用工協(xié)議替代勞動合同新理念
- 二零二五年度社區(qū)養(yǎng)老服務體系合作協(xié)議
- 二零二五年度離婚夫妻財產(chǎn)分割及子女安置及監(jiān)護權變更協(xié)議書4篇
- 二零二五年度養(yǎng)老服務業(yè)勞務用工合作協(xié)議3篇
- 二零二五年度綠色能源項目承攬合同補充協(xié)議2篇
- 2025年度出租車行業(yè)車輛安全檢測合同協(xié)議8篇
- 二零二五年度水利工程監(jiān)理工程師資格認定補充協(xié)議3篇
- 二零二五年度居民區(qū)害蟲防治服務合同協(xié)議書
- 安徽省定遠重點中學2024-2025學年第一學期高二物理期末考試(含答案)
- 教育教學質(zhì)量經(jīng)驗交流會上校長講話:聚焦課堂關注個體全面提升教育教學質(zhì)量
- 2024人教新目標(Go for it)八年級英語上冊【第1-10單元】全冊 知識點總結
- 劇本殺店長合同范例
- 華中師范大學第一附中2025屆高考仿真模擬數(shù)學試卷含解析
- 農(nóng)村自建房施工合同模板
- GB/T 44731-2024科技成果評估規(guī)范
- 影視動畫設計與制作合同
- 2023學年廣東省深圳實驗學校初中部九年級(下)開學語文試卷
- 企業(yè)新員工培訓師帶徒方案
- 2025屆河南省鄭州一中高三物理第一學期期末學業(yè)水平測試試題含解析
評論
0/150
提交評論