五千年(敝帚自珍)

主题:【原创】【老兵开源】一个可以计算你写的帖子有多少字的程序 -- 老兵帅客

共:💬27
全看分页树展 · 主题 跟帖
家园 新版本在这里

考虑到ASP.Net服务器还不是很普及,这个程序依然是个Windows Application,但是增加了自动填充能力,用户只需点击Auto Fill既可大功告成。其它说明同上。

下面是全部源代码:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Text;

namespace TextLength

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class MainForm : System.Windows.Forms.Form

{

private System.Windows.Forms.Label lblText;

private System.Windows.Forms.TextBox txtText;

private System.Windows.Forms.Button btnExit;

private System.Windows.Forms.Label lblLength;

private System.Windows.Forms.TextBox txtLength;

private System.Windows.Forms.Button btnAutoFill;

private const int minLength=200;

private string message1="敬祝铁手万事如意、身体健康\n";

private string message2="\n";

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public MainForm()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));

this.lblText = new System.Windows.Forms.Label();

this.txtText = new System.Windows.Forms.TextBox();

this.btnExit = new System.Windows.Forms.Button();

this.lblLength = new System.Windows.Forms.Label();

this.txtLength = new System.Windows.Forms.TextBox();

this.btnAutoFill = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// lblText

//

this.lblText.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

this.lblText.Location = new System.Drawing.Point(24, 16);

this.lblText.Name = "lblText";

this.lblText.Size = new System.Drawing.Size(136, 16);

this.lblText.TabIndex = 0;

this.lblText.Text = "Please fill in the text:";

//

// txtText

//

this.txtText.Location = new System.Drawing.Point(16, 40);

this.txtText.Multiline = true;

this.txtText.Name = "txtText";

this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Both;

this.txtText.Size = new System.Drawing.Size(296, 176);

this.txtText.TabIndex = 1;

this.txtText.Text = "";

this.txtText.TextChanged += new System.EventHandler(this.txtText_TextChanged);

//

// btnExit

//

this.btnExit.Location = new System.Drawing.Point(184, 264);

this.btnExit.Name = "btnExit";

this.btnExit.Size = new System.Drawing.Size(64, 23);

this.btnExit.TabIndex = 3;

this.btnExit.Text = "Exit";

this.btnExit.Click += new System.EventHandler(this.btnExit_Click);

//

// lblLength

//

this.lblLength.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

this.lblLength.Location = new System.Drawing.Point(20, 231);

this.lblLength.Name = "lblLength";

this.lblLength.Size = new System.Drawing.Size(96, 16);

this.lblLength.TabIndex = 4;

this.lblLength.Text = "Current length:";

//

// txtLength

//

this.txtLength.BackColor = System.Drawing.SystemColors.HighlightText;

this.txtLength.Location = new System.Drawing.Point(124, 231);

this.txtLength.Name = "txtLength";

this.txtLength.ReadOnly = true;

this.txtLength.TabIndex = 5;

this.txtLength.Text = "";

//

// btnAutoFill

//

this.btnAutoFill.Location = new System.Drawing.Point(64, 264);

this.btnAutoFill.Name = "btnAutoFill";

this.btnAutoFill.Size = new System.Drawing.Size(64, 24);

this.btnAutoFill.TabIndex = 6;

this.btnAutoFill.Text = "Auto Fill";

this.btnAutoFill.Click += new System.EventHandler(this.btnAutoFill_Click);

//

// MainForm

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(328, 302);

this.Controls.Add(this.btnAutoFill);

this.Controls.Add(this.txtLength);

this.Controls.Add(this.lblLength);

this.Controls.Add(this.btnExit);

this.Controls.Add(this.txtText);

this.Controls.Add(this.lblText);

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.MaximizeBox = false;

this.Name = "MainForm";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Text Length Detector";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new MainForm());

}

private void btnExit_Click(object sender, System.EventArgs e)

{

Dispose();

}

private void txtText_TextChanged(object sender, System.EventArgs e)

{

this.txtLength.Text=Convert.ToString(this.txtText.TextLength);

}

private void btnAutoFill_Click(object sender, System.EventArgs e)

{

if(this.txtText.TextLength<minLength)

{

int difference=(minLength-this.txtText.TextLength)/(message1.Length+message2.Length)+1;

StringBuilder sb=new StringBuilder(this.txtText.Text);

sb.Append("\n");

for(int i=0;i<difference;i++)

{

sb.Append(message1);

sb.Append(message2);

}

this.txtText.Text=sb.ToString();

}

}

}

}

全看分页树展 · 主题 跟帖


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河