淘客熙熙

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

共:💬27
全看分页树展 · 主题
家园 【原创】【老兵开源】一个可以计算你写的帖子有多少字的程序

说明:

这个程序用于计算字符串的长度并显示在特定区域,这样用户可以随时知道帖子长度,并设法使其超过1分/3分的边界线。

由于西西河似乎没有上传附件的功能(至少我是没有找到),只好贴上全部源代码,请用户自行编译。

编译方法:本程序是用C#写成的,因此用户需要有.Net Framework(可以从微软网站下载)或者Visual Studio.Net。然后用户或者使用集成环境构造一个C# Windows Application,加入该源程序并编译;或者使用CSC来编译该源程序。

使用方法:启动编译后的程序,将用户关心的字符串(例如正在编辑的西西河帖子)拷入该程序的上面那个大框子,该程序的下面那个小框子将自动显示该字符串的长度。注意:在该程序中,一个汉字或者一个字符都只算一个字符。

下面是源程序:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

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;

/// <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.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(132, 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 = "";

//

// MainForm

//

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

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

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);

}

}

}

全看分页树展 · 主题


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

Copyright © cchere 西西河