C#真是很方便啊
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace ForrApplication
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- this.btnClean.Click += new EventHandler(CleanTextbox);
- this.btnTrans.Click += new EventHandler(StartToTranse);
- cleanAll = new CleanStream(cleanTarget);
- showMessage = new ShowMessage(showit);
- tMethod = delegate(string beforTran)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = beforTran.Length - 1; i >= 0; i--)
- {
- sb.Append(beforTran[i].ToString());
- }
- return sb.ToString();
- };
- }
- void showit(string message)
- {
- MessageBox.Show("tips:" + message);
- }
- delegate string Trancelation(string beforTran);
- Trancelation tMethod;
- delegate void CleanStream();
- CleanStream cleanAll;
- delegate void ShowMessage(string message);
- ShowMessage showMessage;
- void StartToTranse(object sender, EventArgs e)
- {
- TranceFunction(this.txtUp,this.txtDown);
- }
- private void TranceFunction(TextBox textBox, TextBox textBox_2)
- {
- if (textBox.Text.Length < 1 && textBox_2.Text.Length < 1)
- {
- showit("没有输入字哦");
- return;
- }
- if (textBox.Text.Length > 0 && textBox_2.Text.Length > 0)
- {
- showit("两边都有,您要怎么翻?");
- return;
- }
- if (textBox.Text.Trim() != "")
- {
- textBox_2.Text = tMethod(textBox.Text);
- }
- else if (textBox_2.Text.Trim() != "")
- {
- textBox.Text = tMethod(textBox_2.Text);
- }
- }
- void cleanTarget()
- {
- this.txtUp.Text = "";
- this.txtDown.Text = "";
- }
- void CleanTextbox(object sender, EventArgs e)
- {
- cleanAll();
- }
- }
- }
- namespace ForrApplication
- {
- partial class Form1
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.txtUp = new System.Windows.Forms.TextBox();
- this.txtDown = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.btnClean = new System.Windows.Forms.Button();
- this.btnTrans = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // txtUp
- //
- this.txtUp.Location = new System.Drawing.Point(12, 23);
- this.txtUp.Multiline = true;
- this.txtUp.Name = "txtUp";
- this.txtUp.Size = new System.Drawing.Size(268, 102);
- this.txtUp.TabIndex = 0;
- //
- // txtDown
- //
- this.txtDown.Location = new System.Drawing.Point(12, 159);
- this.txtDown.Multiline = true;
- this.txtDown.Name = "txtDown";
- this.txtDown.Size = new System.Drawing.Size(268, 102);
- this.txtDown.TabIndex = 0;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(12, 8);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(41, 12);
- this.label1.TabIndex = 1;
- this.label1.Text = "正着写";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(14, 141);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(41, 12);
- this.label2.TabIndex = 2;
- this.label2.Text = "反着写";
- //
- // btnClean
- //
- this.btnClean.Location = new System.Drawing.Point(12, 267);
- this.btnClean.Name = "btnClean";
- this.btnClean.Size = new System.Drawing.Size(128, 23);
- this.btnClean.TabIndex = 3;
- this.btnClean.Text = "清空";
- this.btnClean.UseVisualStyleBackColor = true;
- //
- // btnTrans
- //
- this.btnTrans.Location = new System.Drawing.Point(146, 267);
- this.btnTrans.Name = "btnTrans";
- this.btnTrans.Size = new System.Drawing.Size(134, 23);
- this.btnTrans.TabIndex = 4;
- this.btnTrans.Text = "翻译";
- this.btnTrans.UseVisualStyleBackColor = true;
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(292, 292);
- this.Controls.Add(this.btnTrans);
- this.Controls.Add(this.btnClean);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.txtDown);
- this.Controls.Add(this.txtUp);
- this.Name = "Form1";
- this.Text = "snowleung";
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.TextBox txtUp;
- private System.Windows.Forms.TextBox txtDown;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Button btnClean;
- private System.Windows.Forms.Button btnTrans;
- }
- }