设计界面:
一个Label标签,一个命令按钮
编写代码:
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 _1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "";
int number = 0;
for (int x = 1; x < 1000; x++)
{
if ((x % 3) == 0 && (x % 5) != 0)
{
label1.Text += string .Format ("{0,-3:D}",x)+" ";
number++;
}
if (number % 5 == 0) { label1.Text += "\n"; }
}
}
}
}
运行结果: