放一个小工具的源程序

小工具一个,代码很少,功能很简单.

新建C# WinForm工程,主窗体代码如下

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Text
{
 ///


 /// Form1 的摘要说明。
 ///

 public class Form1: System.Windows.Forms.Form
 {
  private System.Windows.Forms.Panel panel1;
  private System.Windows.Forms.Splitter splitter1;
  private System.Windows.Forms.Button btnConvert;
  private System.Windows.Forms.Button btnPaste;
  private System.Windows.Forms.Button btnCopy;
  private System.Windows.Forms.TextBox txtSource;
  private System.Windows.Forms.TextBox txtTarget;
  private System.Windows.Forms.GroupBox grpSource;
  private System.Windows.Forms.GroupBox grpTarget;
  ///
  /// 必需的设计器变量。
  ///

  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   // 在 InitializeComponent 调用后添加任何构造函数代码
   this.txtTarget.Text="";
   this.txtSource.Text="";
  }

  ///


  /// 清理所有正在使用的资源。
  ///

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  ///


  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///

  private void InitializeComponent()
  {
   this.txtSource = new System.Windows.Forms.TextBox();
   this.btnConvert = new System.Windows.Forms.Button();
   this.txtTarget = new System.Windows.Forms.TextBox();
   this.panel1 = new System.Windows.Forms.Panel();
   this.btnCopy = new System.Windows.Forms.Button();
   this.btnPaste = new System.Windows.Forms.Button();
   this.grpSource = new System.Windows.Forms.GroupBox();
   this.splitter1 = new System.Windows.Forms.Splitter();
   this.grpTarget = new System.Windows.Forms.GroupBox();
   this.panel1.SuspendLayout();
   this.grpSource.SuspendLayout();
   this.grpTarget.SuspendLayout();
   this.SuspendLayout();
   //
   // txtSource
   //
   this.txtSource.Dock = System.Windows.Forms.DockStyle.Fill;
   this.txtSource.Location = new System.Drawing.Point(3, 16);
   this.txtSource.Multiline = true;
   this.txtSource.Name = "txtSource";
   this.txtSource.ScrollBars = System.Windows.Forms.ScrollBars.Both;
   this.txtSource.Size = new System.Drawing.Size(510, 125);
   this.txtSource.TabIndex = 0;
   this.txtSource.Text = "txtSource";
   //
   // btnConvert
   //
   this.btnConvert.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnConvert.Location = new System.Drawing.Point(150, 8);
   this.btnConvert.Name = "btnConvert";
   this.btnConvert.Size = new System.Drawing.Size(114, 20);
   this.btnConvert.TabIndex = 1;
   this.btnConvert.Text = "处理(&C)";
   this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click);
   //
   // txtTarget
   //
   this.txtTarget.Dock = System.Windows.Forms.DockStyle.Fill;
   this.txtTarget.Location = new System.Drawing.Point(3, 16);
   this.txtTarget.Multiline = true;
   this.txtTarget.Name = "txtTarget";
   this.txtTarget.ReadOnly = true;
   this.txtTarget.ScrollBars = System.Windows.Forms.ScrollBars.Both;
   this.txtTarget.Size = new System.Drawing.Size(510, 100);
   this.txtTarget.TabIndex = 2;
   this.txtTarget.Text = "textBox2";
   //
   // panel1
   //
   this.panel1.Controls.Add(this.btnCopy);
   this.panel1.Controls.Add(this.btnPaste);
   this.panel1.Controls.Add(this.btnConvert);
   this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
   this.panel1.Location = new System.Drawing.Point(0, 0);
   this.panel1.Name = "panel1";
   this.panel1.Size = new System.Drawing.Size(516, 36);
   this.panel1.TabIndex = 3;
   //
   // btnCopy
   //
   this.btnCopy.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnCopy.Location = new System.Drawing.Point(288, 8);
   this.btnCopy.Name = "btnCopy";
   this.btnCopy.Size = new System.Drawing.Size(114, 20);
   this.btnCopy.TabIndex = 3;
   this.btnCopy.Text = "复制(&F)";
   this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
   //
   // btnPaste
   //
   this.btnPaste.FlatStyle = System.Windows.Forms.FlatStyle.System;
   this.btnPaste.Location = new System.Drawing.Point(10, 8);
   this.btnPaste.Name = "btnPaste";
   this.btnPaste.Size = new System.Drawing.Size(114, 20);
   this.btnPaste.TabIndex = 2;
   this.btnPaste.Text = "粘贴(&Z)";
   this.btnPaste.Click += new System.EventHandler(this.btnPaste_Click);
   //
   // grpSource
   //
   this.grpSource.Controls.Add(this.txtSource);
   this.grpSource.Dock = System.Windows.Forms.DockStyle.Top;
   this.grpSource.Location = new System.Drawing.Point(0, 36);
   this.grpSource.Name = "grpSource";
   this.grpSource.Size = new System.Drawing.Size(516, 144);
   this.grpSource.TabIndex = 4;
   this.grpSource.TabStop = false;
   this.grpSource.Text = "来源";
   //
   // splitter1
   //
   this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
   this.splitter1.Location = new System.Drawing.Point(0, 180);
   this.splitter1.Name = "splitter1";
   this.splitter1.Size = new System.Drawing.Size(516, 3);
   this.splitter1.TabIndex = 5;
   this.splitter1.TabStop = false;
   //
   // grpTarget
   //
   this.grpTarget.Controls.Add(this.txtTarget);
   this.grpTarget.Dock = System.Windows.Forms.DockStyle.Fill;
   this.grpTarget.Location = new System.Drawing.Point(0, 183);
   this.grpTarget.Name = "grpTarget";
   this.grpTarget.Size = new System.Drawing.Size(516, 119);
   this.grpTarget.TabIndex = 6;
   this.grpTarget.TabStop = false;
   this.grpTarget.Text = "结果";
   //
   // frmMain
   //
   this.AutoScale = false;
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.ClientSize = new System.Drawing.Size(516, 302);
   this.Controls.Add(this.grpTarget);
   this.Controls.Add(this.splitter1);
   this.Controls.Add(this.grpSource);
   this.Controls.Add(this.panel1);
   this.Name = "frmMain";
   this.Text = "加插空格工具";
   this.panel1.ResumeLayout(false);
   this.grpSource.ResumeLayout(false);
   this.grpTarget.ResumeLayout(false);
   this.ResumeLayout(false);

  }
  #endregion

  ///


  /// 应用程序的主入口点。
  ///

  [STAThread]
  static void Main()
  {
   Application.EnableVisualStyles();
   Application.Run(new frmMain());
  }

  private void btnPaste_Click(object sender, System.EventArgs e)
  {
   this.txtSource.Paste();
  }

  private void btnCopy_Click(object sender, System.EventArgs e)
  {
   this.txtTarget.Copy();  
  }

  private void btnConvert_Click(object sender, System.EventArgs e)
  {
   this.Cursor=System.Windows.Forms.Cursors.WaitCursor;
   try
   {
    string rtnValue=string.Empty;
    string lineString=string.Empty;

    for(int i=0;i    {
     lineString=this.txtSource.Lines[i];
   
     for(int j=0;j<1000000;j++)
     {
      if((2*j+1)      {
       lineString=lineString.Insert(2*j+1," ");
      }
      else
      {
       break;
      }
     }
     lineString+="\r\n";
     rtnValue+=lineString;   
    }
  
    this.txtTarget.Text=rtnValue;
   }
   catch(Exception ex)
   {
    string strCaption="出错了";
    string strMessage=string.Format("错误来源: {0}\r\n错误内容: {1}",ex.Source,ex.Message);
    System.Windows.Forms.MessageBoxButtons mbb=System.Windows.Forms.MessageBoxButtons.OK;
    System.Windows.Forms.MessageBoxIcon mbi=System.Windows.Forms.MessageBoxIcon.Hand;
    System.Windows.Forms.MessageBoxDefaultButton mbdb=System.Windows.Forms.MessageBoxDefaultButton.Button1;
    MessageBox.Show(this,strMessage,strCaption,mbb,mbi,mbdb);
   }
   finally
   {
    this.Cursor=System.Windows.Forms.Cursors.Default;
   }
  }

 }//End Class
}//End Namespace

posted @ 2005-09-11 22:22  置身珠海,学习与奋斗  阅读(353)  评论(0编辑  收藏  举报