5操縱回車事務來驗證錄入的內容長度是否合適自界說長度 。
private void textBox2_KeyDown(object ser, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
checklength();
}
}
}

6驗證成果合適要求 , 附完整源代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checklength()
{
int m = int.Parse(textBox1.Text);//界說長度
int n = textBox2.Text.Length;//錄入內容長度
if (m != n)
{
MessageBox.Show("輸入長度錯誤!");
textBox2.BackColor = Color.Red;
textBox2.SelectAll();
}
else
{
MessageBox.Show("OK!");
textBox2.BackColor = Color.White;
textBox2.SelectAll();
}
}
private void textBox2_KeyDown(object ser, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
checklength();
}
}
}
}



以上內容就是C#實現輸入內容長度檢查的內容啦 , 希望對你有所幫助哦!
猜你喜歡
- 隊列的基本操作在編程語言中怎樣實現
- 蘋果筆記本Mac無法輸入jkluio怎么辦
- macbook卡在登錄界面鍵盤無反應密碼無法輸入
- 三國演義第十六回主要內容 三國演義第十六回主要內容是什么
- 駱駝祥子第九章主要內容駱駝祥子第九章講了什么
- 剃頭大師課文主要內容 課文剃頭大師的主要內容是什么
- 如何用搜狗輸入法打出花漾字
- 快手怎么實現倒計時拍攝
- 世界地球日手抄報內容,世界地球日手抄報內容畫法
- 三國演義主要內容 三國演義內容簡介
