五千年(敝帚自珍)

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

共:💬27
全看分页树展 · 主题 跟帖
家园 只是玩笑 - 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);

}

}

}

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

全看分页树展 · 主题 跟帖


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

Copyright © cchere 西西河