using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace frmexe01
{
public partial class frmExe03 : Form
{
public frmExe03()
{
InitializeComponent();
}
private void frmExe03_Load(object sender, EventArgs e)
{
txtText.Text = "我爱北京***,***上太阳升.";
}
private void btnLeft_Click(object sender, EventArgs e)
{
for (int i = 0; i < txtText.Text.Length; i++)
{
txtText.Text = txtText.Text.Substring(1) + txtText.Text.Substring(0, 1);
txtText.Update();
//for(int j = 0;j <10000000; j++)
//{
//}
System.Threading.Thread.Sleep(500);
}
}
private void button1_Click(object sender, EventArgs e)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for(int i = 1;i <= 1000; i++)
{
textBox1.Text = i.ToString();
//textBox1.Update();
}
watch.Stop();
MessageBox.Show(string.Format("共用时间:{0}", watch.Elapsed.Milliseconds.ToString()));
}
private void btnRight_Click(object sender, EventArgs e)
{
for (int i = 0; i < txtText.Text.Length; i++)
{
txtText.Text = txtText.Text.Substring(txtText.Text.Length - 1) +
txtText.Text.Substring(0, txtText.Text.Length - 1);
txtText.Update();
//for(int j = 0;j <10000000; j++)
//{
//}
System.Threading.Thread.Sleep(500);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace frmexe01
{
public partial class frmExe02 : Form
{
public frmExe02()
{
InitializeComponent();
}
private void btnCompute_Click(object sender, EventArgs e)
{
int start,end;
if(!int.TryParse(txtStart.Text, out start))
{
MessageBox.Show("起始值输入有误,请重新输入!");
txtStart.Focus();
txtStart.SelectAll();
return;
}
if (!int.TryParse(txtEnd.Text, out end))
{
MessageBox.Show("终止值输入有误,请重新输入!");
txtEnd.Focus();
txtEnd.SelectAll();
return;
}
if(start>end)
{
MessageBox.Show("起始值必须小于终止值!请重新输入!");
txtStart.Focus();
txtStart.SelectAll();
return;
}
int sum = 0;
for(int i = start; i <= end; i++)
{
sum = sum + i;
}
txtResult.Text = sum.ToString();
}
private void txtStart_TextChanged(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtStart_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox texBox = sender as TextBox;//注意触发事件
// if(e.KeyChar < 48 || e.KeyChar > 57)
if(e.KeyChar < '0'|| e.KeyChar > '9')
{
e.Handled = true;
}
//MessageBox.Show(txtStart.SelectionStart.ToString());
if(texBox.SelectionStart == 0 && e.KeyChar == '0')
{
//SelectionStart光标所处位置
e.Handled = true;
}
if(e.KeyChar == 8)
{
e.Handled = false;
}
}
}
}