五千年(敝帚自珍)

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

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

说明:

这个程序用于计算字符串的长度并显示在特定区域,这样用户可以随时知道帖子长度,并设法使其超过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);

}

}

}

家园 几点意见:你要是关心大家涨分的问题,将这个程序做成WEB吗?

大家就不用下在什么.NET Framework,用什么csc编译了。

另外,如果字数不够200,程序应该自动增加点“垃圾”内容,比如表情点看全图,标点符号(▲&#9658;????&#9618;♀&#9788;),图片什么的点看全图

外链图片需谨慎,可能会被源头改

这样对大家才有“帮助”,也可以把铁手气死过去!

家园 或者我干脆做个填充器算了

用户只需填上标题,剩下的就不用关心了。

肚皮要笑破了。

看来我需要举报点什么了。

家园 【严正声明】我的目的是帮助大家高效率地发帖挣分,而不是制造垃圾

有人良心大大地坏了。

家园 新版本在这里

考虑到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();

}

}

}

}

家园 老兵在传播病毒,大家不要上他的当
家园 如果有那样的东西出现,我会毫不犹豫的封。
家园 只是玩笑 - Web版本,功能等同于Windows新版

不过我还真写了一个Web版,是用ASP.Net做的,有兴趣的可以玩玩,不过被铁手封了可别怪我。

下面是页面的源代码:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>WebForm1</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>

<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

<FONT face="宋体">

<asp:Label id="lblText" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 32px" runat="server"

Width="192px" Height="16px">Please fill in the text:</asp:Label>

<asp:TextBox id="txtText" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 56px" runat="server"

Width="296px" Height="176px" TextMode="MultiLine"></asp:TextBox>

<asp:Label id="lblLength" style="Z-INDEX: 103; LEFT: 56px; POSITION: absolute; TOP: 248px"

runat="server" Width="128px" Height="16px">Current length:</asp:Label>

<asp:TextBox id="txtLength" style="Z-INDEX: 104; LEFT: 192px; POSITION: absolute; TOP: 248px"

runat="server" Width="120px" ReadOnly="True"></asp:TextBox>

<asp:Button id="btnAutoFill" style="Z-INDEX: 105; LEFT: 96px; POSITION: absolute; TOP: 304px"

runat="server" Width="81px" Height="24" Text="Auto Fill"></asp:Button>

<asp:Button id="btnGetLength" style="Z-INDEX: 106; LEFT: 216px; POSITION: absolute; TOP: 304px"

runat="server" Width="80px" Height="24" Text="Get Length"></asp:Button></FONT>

</form>

</body>

</HTML>

下面是对应的处理程序:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace WebApplication1

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label lblText;

protected System.Web.UI.WebControls.TextBox txtText;

protected System.Web.UI.WebControls.Label lblLength;

protected System.Web.UI.WebControls.TextBox txtLength;

protected System.Web.UI.WebControls.Button btnAutoFill;

private const int minLength=200;

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

protected System.Web.UI.WebControls.Button btnGetLength;

private string message2="\n";

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

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

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

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

/// </summary>

private void InitializeComponent()

{

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

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

this.btnGetLength.Click += new System.EventHandler(this.btnGetLength_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

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

{

}

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

{

if(this.txtText.Text.Length<minLength)

{

int difference=(minLength-this.txtText.Text.Length)/(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();

}

}

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

{

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

}

}

}

再次声明,这个只是用来玩玩,不要真的用来制造垃圾。

家园 怎么可能是病毒,我提供全部源代码了,愿者上钩
家园 老兵大大的狡猾

谁用了这个程序就是变相的承认自己是“SB”

家园 离右派只有五十步了。外面包个循环,就是炸坛机!
家园 这么长,看得我头晕,宁愿相信梦里依稀

再说,能成功编译你这程序的,就能自己写。这话不错吧?

家园 老兵这又何必呢?

There is a line we should not cross.

家园 道理我当然是明白的

能够把程序编译成功的,不会在乎多敲几个字;真正懒的,也不会去编译程序了。

原本这个程序的目的只是为了检验字符串的长度:在.Net下面,中文和英文字符的长度是一样的,都是Unicode。看了Highway的回帖,我才想起要做个填充器。

纯属搞笑。

这次阿康被我赚了。

遗憾地是,西西河真正理解我的人,这几天不在。

谢了。

家园 老天!

本来就是搞笑,居然真会有人上当!

不好意思,得罪了。

全看树展主题 · 分页首页 上页
/ 2
下页 末页


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

Copyright © cchere 西西河