看代码。
程序代码:
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace BCCN.CSharp.Demo
{
public class Program
{
public static void Main()
{
Application.Run( new FrmDemo());
}
}
public class FrmDemo : Form
{
/*
* Fields
*/
private TextBox txtNumber;
private TextBox txtResult;
private Button btnCount;
public FrmDemo()
{
Initial();
}
/*
* Help methods
*/
private void Initial()
{
//
// Initial txtBox Number.
//
this.txtNumber = new TextBox();
this.txtNumber.Name = "txtNumber";
this.txtNumber.Location = new Point(50, 100);
this.txtNumber.Size = new Size( 100, 30);
//
// Initial txtbox result.
//
this.txtResult = new TextBox();
this.txtResult.Name = "txtResult";
this.txtResult.Location = new Point( 10 + 100 + 50, 100);
this.txtResult.Size = this.txtNumber.Size;
this.txtResult.Enabled = false;
//
// Initial button count.
//
this.btnCount = new Button();
this.btnCount.Name = "btnCount";
this.btnCount.Text = "Count";
this.btnCount.Location = new Point( 50, 100 + 30 + 15);
this.btnCount.Click += new EventHandler( ButtonCount_Click);
//
// Initial form.
//
this.Size = new Size(400, 438);
this.Location = new Point( 300, 245);
this.Controls.Add( this.txtNumber);
this.Controls.Add( this.txtResult);
this.Controls.Add( this.btnCount);
}
/*
* Handlers
*/
private void ButtonCount_Click( object sender, EventArgs e)
{
try
{
string numStr = this.txtNumber.Text;
double numberDouble = double.Parse( numStr);
long numberLong = (long)numberDouble;
if ( numberLong % 50 == 0)
{
this.txtResult.Text = "除得的是整数";
}
else
{
this.txtResult.Text = "除得的不是整数";
}
}
catch
{
// eat error.
MessageBox.Show( "Format error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtNumber.SelectAll();
}
}
}
}