3. 用c#设计一个Windows应用程序,程序启动后,用户在文本框中输入一个正整数,单击[提取]按钮,

程序在列表框中单独输出整数各位上的值。如下图所示

提醒两点:
1. 你需要一个 validator, 就是说只允许正整数出现。所以在不符合条件时出现一条提示符,同时“提取”按钮不能点。
2. 如果是一个比较严肃的程序,你需要控制输入长度,当然只是做着玩无所谓。

public partial class Form1 : Form
{
private Regex regx = new Regex(@"^\d+$");

public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Visible=!regx.IsMatch(textBox1.Text); //错误提示
button1.Enabled = regx.IsMatch(textBox1.Text); //按钮不能点击。
}

private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < textBox1.Text.Length; i++)
{
listBox1.Items.Add("position " + (i + 1).ToString() + " is " + textBox1.Text[i]);
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-02-25
string num = 56666;
string[] numArray = new String[num.length);
for(int i = 0; i < num.length;i++)
{
if(i==num.length -1)
{
break;
}
numArray[i] = num.substring(i,i+1);
}

for(int i = 0;i< numArray.length;i++)
{
tb.Text = "第"+(i+1)+"位的数值为:"+numArray[i].Tostring();
}

基本思路就是这个样子了!剩下的慢慢的来琢磨吧!
第2个回答  2011-02-24
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < textBox1.Text.Length; i++)
{
listBox1.Items.Add(string.Format("第{0}位的值为:{1}", i + 1, textBox1.Text[i]));
}
}
}
}

需要完整程序的话,留下邮箱,我打包发给你
相似回答