主题:【原创】【老兵开源】一个可以计算你写的帖子有多少字的程序 -- 老兵帅客
考虑到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();
}
}
}
}
- 相关回复 上下关系8
😁几点意见:你要是关心大家涨分的问题,将这个程序做成WEB吗? Highway 字344 2004-06-13 07:25:00
😁如果有那样的东西出现,我会毫不犹豫的封。 铁手 字0 2004-06-13 08:58:58
😄只是玩笑 - Web版本,功能等同于Windows新版 老兵帅客 字4482 2004-06-13 09:08:52
😄新版本在这里
😠【严正声明】我的目的是帮助大家高效率地发帖挣分,而不是制造垃圾 老兵帅客 字26 2004-06-13 07:45:43
😉或者我干脆做个填充器算了 老兵帅客 字96 2004-06-13 07:42:16