winform 记事本编程部分

textbox:  

属性:

    text:文本   

    selectedtext:获取或设置选中文本  

    canundo:是否能够撤销

 方法:  

 undo:撤销  

 clearundo:清空撤销缓冲区  

 cut:剪切   

copy:复制   

Paste:粘贴  

 SelectAll:全选

对话框:  showdialog();显示对话框,返回一个dialogresult的枚举类型

     colorDialog:color属性,用来获取颜色

     folderBrowserDialog:SelectedPath选中路径  

    fontDialog:font属性,返回一个font类型的值,里面存储了关于字体的设置

    openFileDialog:   filename获取或设置文件路径包含文件名

     filenames 是文件路径字符串数组   

    filter:文件筛选器 格式为 提示文本一|*.后缀|提示文本二|*.后缀|提示文本三|*.后缀

    saveFileDialog1:   filename获取或设置文件路径包含文件名   

    filenames 是文件路径字符串数组  

    filter:文件筛选器 格式为 提示文本一|*.后缀|提示文本二|*.后缀|提示文本三|*.后缀

流:  

输入流:  

       string filename = openFileDialog1.FileName;             

      //通过读入流进行文件读取         

       StreamReader sr = new StreamReader(filename);             

      textBox1.Text = sr.ReadToEnd();            

       sr.Close();

 输出流:    

      string filename = saveFileDialog1.FileName;                

     //写入流,可以在硬盘上创建文件,并为文件写入信息                   

     StreamWriter sw = new StreamWriter(filename);               

      sw.Write(this.textBox1.Text);                 

    sw.Close();  this:代表的它所在的那个类当前对象

打印:

 打印对话框:printdialog  

页面设置:pagesetupdialog   

 这两个对话框都需要通过设置printdocument来指定打印对象  

printdocument:打印对象,必须要有,一块画板,用于打印机与打印内容之间中转,打印机打印的是printdoment  printDocument1_PrintPage:事件,每打印一页之前触发,用于给printdocument指定打印内容  通过画板把内容画到打印对象的页上:  

 System.Drawing.Font f = new System.Drawing.Font("宋体",12);           

  e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aqua,5,5);

 最后打印: 打印对话框那,如果打印对话框返回确定打印,就执行printdocument.print();

///////例如新建

  private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)    

     {

            if (this.textBox1.Text.Length > 0)         //   

                 {               

                          DialogResult drg = MessageBox.Show("是否进行保存?", "保存对话框", MessageBoxButtons.YesNo);         

                        if (DialogResult.Yes == drg)                

                                   {                    

                                               if (files == null)               

                                                             {                       

                                                                      DialogResult dr = saveFileDialog1.ShowDialog();              

                                                                      if (dr == DialogResult.OK)                      

                                                                           {          string filename = saveFileDialog1.FileName;              

                                                                                     //写入流,可以在硬盘上创建文件,并为文件写入信息                           

                                                                                   StreamWriter sw = new StreamWriter(filename);                            

                                                                                   sw.Write(this.textBox1.Text);                           

                                                                                   sw.Close();                        

                                                                             }                    

                                                              }                    

                                                   else                    

                                                             {                       

                                                                        //写入流,可以在硬盘上创建文件,并为文件写入信息                       

                                                                          StreamWriter sw = new StreamWriter(files);                        

                                                                           sw.Write(this.textBox1.Text);                        

                                                                          sw.Close();                   

                                                              }               

                                        }          

                                   }

            files = null;           

             this.textBox1.Text = "";        

     }

 

posted on 2015-03-09 22:43  极度猎隼  阅读(170)  评论(0编辑  收藏  举报