如何从.net C#中的按钮单击事件生成自动ID并在文本框中显示 [英] How to generate auto id and show in textbox from button click event in .net c#
本文介绍了如何从.net C#中的按钮单击事件生成自动ID并在文本框中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从.net中的按钮单击事件生成自动ID并在文本框中显示c#
How to generate auto id and show in textbox from button click event in .net c#
推荐答案
hi ..
这可能对您有帮助.
http://www.dotnetperls.com/random [
hi..
this may help you.
http://www.dotnetperls.com/random[^]
您可以使用随机类 [
Hi,
You can use Random Class[^] to generate Random ID.
Try this:
private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch ;
for(int i=0; i<size;> {
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
builder.Append(ch);
}
if(lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
此函数将返回随机ID.
--Amit
This function will return the Random ID.
--Amit
声明一个全局变量,并在每次单击时将其递增
declare a global variable and increment it on each click
int id = 1;
//on button click
id++;
这篇关于如何从.net C#中的按钮单击事件生成自动ID并在文本框中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文