0

my code is:

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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        double num;
        string text = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void calFactorial_TextChanged(object sender, EventArgs e)
        {
            if (calFactorial.Text != "")
            {
                if (!(Char.IsNumber(calFactorial.Text, 0)))
                {
                    factLabel.Text = "Enter number only";
                }
                else if (Convert.ToDouble(calFactorial.Text) == 0)
                {
                    factLabel.Text = "Please provide a Number greater than 0.";
                }                           
            }
            else
            {
                factLabel.Text = "Please Enter Number";
            }
        }

        private void factorial_Click(object sender, EventArgs e)
        {
            if (calFactorial.Text == "")
            {
                factLabel.Text = "Please enter a number";
            }                      

            else
            {    
                num = Convert.ToDouble(calFactorial.Text);
                RichTextBox richTextBox = new RichTextBox();                
                foreach (Control removeControl in Controls)
                {
                    removeControl.Hide();
                    calFactorial.Show();
                    factLabel.Show();
                    factorial.Show();
                }
                Button clear = new Button();
                clear.Location = new Point(500, 150);
                richTextBox.Location = new Point(100, 100);
                richTextBox.Size = new Size(300, 200);
                clear.Text = "Clear";
                this.Controls.Add(clear);
                this.Controls.Add(richTextBox);
                double fact = 1;               
                for (double i = num; i >= 1; i--)
                {
                    fact = fact * i;
                }
                richTextBox.Text = text + "The factorial of " + Convert.ToString(num) + " is: " + Convert.ToString(fact) + "\n";
                text = richTextBox.Text;
                clear.Click += new EventHandler(ClearClick);
                richTextBox.TextChanged += new EventHandler(ClearClick);             
            }
        }

        private void ClearClick(object sender, EventArgs e)
        {            
            foreach (Control removeControl in Controls)
            {
                removeControl.Hide();
                calFactorial.Show();
                factLabel.Show();
                factorial.Show();
                calFactorial.Text = "";
            }

        }

    }
}

Edited by Reverend Jim: Fixed formatting

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by khanrock
0

nw tell me how to reset contents of richtextbox on clicking clear button....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.