MainForm.cs
上传用户:linger1010
上传日期:2008-12-08
资源大小:561k
文件大小:1k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace CalculateSum
- {
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- }
- private void m_btnCalculate_Click(object sender, EventArgs e)
- {
- try
- {
- Cursor.Current = Cursors.WaitCursor;
- m_btnCalculate.Enabled = false;
- int target = Int32.Parse(m_txtTarget.Text);
- int sum = 0;
- for(int i = 1; i <= target; i++)
- sum += i;
- MessageBox.Show(
- String.Format("Result: {0}.", sum),
- "Finished",
- MessageBoxButtons.OK,
- MessageBoxIcon.Asterisk,
- MessageBoxDefaultButton.Button1);
- }
- catch(Exception ex)
- {
- MessageBox.Show(
- String.Format("Some error occurs. Details: {0}.", ex.Message),
- "Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Asterisk,
- MessageBoxDefaultButton.Button1);
- }
- finally
- {
- Cursor.Current = Cursors.Default;
- m_btnCalculate.Enabled = true;
- }
- }
- }
- }