贴源码。c#写的指法练习,编写中文练习的人也可参考。

阿牛138588 2008-07-11 03:06:03
不管别人写得怎样,这是花2小时替我侄女写的。
欢迎程序员们加入群:63979707
欢迎高手们给出建议
跟贴接分!


using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 指法
{
public partial class Form1 : Form
{
public class sLabel : Label
{
public sLabel()
{
this.Font = new Font("Courier New", 15);
this.Anchor = AnchorStyles.Left | AnchorStyles.Right;
this.Visible = false;
this.AutoSize = true;
this.Height = 27;
this.BorderStyle = BorderStyle.None;

}
}
public class sRichtextbox : RichTextBox
{
public sRichtextbox()
{
this.Font = new Font("Courier New", 15);
this.Height = 27;
this.ForeColor = Color.Black;
this.Anchor = AnchorStyles.Left | AnchorStyles.Right;
this.Visible = false;
this.ScrollBars = RichTextBoxScrollBars.None;
}
}

public Form1()
{
InitializeComponent();
this.MinimumSize = new Size(597, 405);
this.StartPosition = FormStartPosition.CenterScreen;
}

List<Label> lstLable = new List<Label>();
List<RichTextBox> lstRichTextBox = new List<RichTextBox>();
int NowWorldLengt = 0;
private void Form1_Resize(object sender, EventArgs e)
{
int intWidth = this.ClientSize.Width;
bool bVisible = false;
for (int i = 0; i < 30; i++)
{
int y = i * 55 +70; //27为toolstrip高度
if (y + 5 > this.ClientSize.Height)
{
ShowRichtextboxCount = i;
bVisible = false;
}
else
bVisible = true;
lstLable[i].Location = new Point(0, y-45);
lstLable[i].Width = intWidth;
lstLable[i].Visible = bVisible;
lstRichTextBox[i].Location = new Point(0,y-22);
lstRichTextBox[i].Width = intWidth;
lstRichTextBox[i].Visible = bVisible;
}

switch (iCharacter)
{
case 1:
a_z(null, null);
break;
case 2:
A_z(null, null);
break;
case 3:
A_z_Num(null, null);
break;
}

}

Timer timer = new Timer(); //计时器
ToolStripLabel tsLSpeed = new ToolStripLabel();
int iCharacter = 0;
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 30; i++)
{
sLabel a = new sLabel();
sRichtextbox b = new sRichtextbox();
lstLable.Add(a);
lstRichTextBox.Add(b);
this.Controls.Add(a);
this.Controls.Add(b);
b.Tag = i;
b.TextChanged += inputboxTextChange;
b.SelectionChanged += inputboxSelectionChange;
b.KeyDown += inputboxKeyDown;
b.GotFocus += inputFocus;
}
ToolStrip ts = new ToolStrip();
ToolStripButton tb1;
tb1=AddNewTsB("纯小写字母训练", ref ts);
tb1.Click += a_z;

tb1 = AddNewTsB("大小写字母训练", ref ts);
tb1.Click += A_z;

tb1 = AddNewTsB("字母及数字训练", ref ts);
tb1.Click += A_z_Num;

ToolStripSeparator tss1 = new ToolStripSeparator();
ts.Items.Add(tss1);
AddNewTsB("当前速度", ref ts);
ts.Items.Add(tsLSpeed);
this.Controls.Add(ts);
timer.Interval = 1000;
timer.Tick += CountTime;
Form1_Resize(null,null);

}
ToolStripButton AddNewTsB(string strText,ref ToolStrip ts)
{
ToolStripButton tb1=new ToolStripButton();
tb1.Text = strText;
tb1.DisplayStyle = ToolStripItemDisplayStyle.Text;
ts.Items.Add(tb1);
return tb1;
}

int RightKey = 0; //正确字符数量
int WrongKey = 0; //错误字符数量
int ElapseTime = 0;//使用时间数量(秒)
void a_z(object sender, EventArgs e)
{
getText('a', 'z');
iCharacter = 1;
}
void A_z(object sender, EventArgs e)
{
getText('A', 'z');
iCharacter = 2;
}
void A_z_Num(object sender, EventArgs e)
{
getText('0', 'z');
iCharacter = 3;
}
void getText(int miniValue, int maxValue)
{
//计算当前看得到的字符
NowWorldLengt = (this.ClientSize.Width - 10) / 12;
ElapseTime = 0;
RightKey = 0;
WrongKey = 0;
timer.Enabled = true;
int iTextLength = 0;
Random rd = new Random(Guid.NewGuid().GetHashCode());
Regex reg = new Regex(@"(\d|\w)");
Regex reg2 = new Regex(@"\w");
for (int l1 = 0; l1 < 30; l1++)
{
StringBuilder sb = new StringBuilder();
while (iTextLength < NowWorldLengt)
{
char c = (char)rd.Next(miniValue, maxValue);
if (miniValue == '0')
{
if (reg.Match(c.ToString()).Success && c!='_')
{
sb.Append(c);
iTextLength++;
Application.DoEvents();
}
}
else
{
if (reg2.Match(c.ToString()).Success && c != '_')
{
sb.Append(c);
iTextLength++;
}
}
}
iTextLength = 0;
lstLable[l1].Text = sb.ToString();
lstRichTextBox[l1].Clear();
}
lstRichTextBox[0].Focus();
}
void CountTime(object sender, EventArgs e)
{
ElapseTime++;
tsLSpeed.Text = "正确:" + RightKey.ToString() + " 错误:" + WrongKey.ToString() + " 费时:" + ElapseTime.ToString()+" 速度:" +(RightKey*60/ElapseTime).ToString()+"/分钟";
}
int NowIndex = -1; //当前正在输入的richtextbox
void inputFocus(object sender, EventArgs e)
{
RichTextBox b=(RichTextBox) sender;
NowIndex = (int)b.Tag;
}
void inputboxKeyDown(object sender, KeyEventArgs e)
{
if (e.Control || e.KeyValue==16)
return;
RichTextBox rb=(RichTextBox) sender;
int iDiff = 32;
if (Control.IsKeyLocked(Keys.CapsLock) && e.Shift)
iDiff *= -1;
else
{
if (e.Shift || Control.IsKeyLocked(Keys.CapsLock))
iDiff = 0;
}
if (e.KeyValue + iDiff == lstLable[NowIndex].Text[rb.SelectionStart])
{
rb.SelectionColor = Color.Black;
RightKey++;
}
else
{
rb.SelectionColor = Color.Red;
WrongKey++;
}
}
...全文
495 67 打赏 收藏 转发到动态 举报
写回复
用AI写文章
67 条回复
切换为时间正序
请发表友善的回复…
发表回复
shadowjl 2008-07-14
  • 打赏
  • 举报
回复
做你侄女真是幸福
Shadow_White 2008-07-14
  • 打赏
  • 举报
回复
学习、学习。
游北亮 2008-07-14
  • 打赏
  • 举报
回复
呵呵,不错,有有趣的玩意,收了。
ldp333 2008-07-13
  • 打赏
  • 举报
回复
记录在案
yangyibang 2008-07-12
  • 打赏
  • 举报
回复
高人
  • 打赏
  • 举报
回复
敢问你侄女年龄几何?
anan221 2008-07-12
  • 打赏
  • 举报
回复
顶下
wcbenben 2008-07-12
  • 打赏
  • 举报
回复
顶完再看!
amandag 2008-07-12
  • 打赏
  • 举报
回复
up
格拉 2008-07-12
  • 打赏
  • 举报
回复
LZ强人!
c863123 2008-07-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lxuan_025 的回复:]



i dig three
[/Quote]
sxmonsy 2008-07-12
  • 打赏
  • 举报
回复
学习+接分
qinqinhao 2008-07-12
  • 打赏
  • 举报
回复
ding
ding
sj6071 2008-07-12
  • 打赏
  • 举报
回复
害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害厉
r_swordsman 2008-07-12
  • 打赏
  • 举报
回复
2小时写出来。厉害
yeemio 2008-07-12
  • 打赏
  • 举报
回复
学习一下~
wuyi8808 2008-07-12
  • 打赏
  • 举报
回复
mark
我姓区不姓区 2008-07-12
  • 打赏
  • 举报
回复
up
zzchyrails 2008-07-12
  • 打赏
  • 举报
回复
学习,DDD
xiaoaogong9 2008-07-12
  • 打赏
  • 举报
回复
学习学习!!!
加载更多回复(46)

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧