Monday 27 February 2012

Events Of Mouse (Enter, Leave) & TextBox(KeyPress)

Events Of Mouse (Enter, Leave) & TextBox (KeyPress) In Windows Form

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 Events
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_MouseEnter(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Red;
            textBox1.ForeColor = Color.White;
        }


        private void textBox1_MouseLeave(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Wheat;
            textBox1.ForeColor = Color.Black;
        }

        private void textBox2_MouseEnter(object sender, EventArgs e)
        {
            textBox2.BackColor = Color.Red;
            textBox2.ForeColor = Color.White;

        }

        private void textBox2_MouseLeave(object sender, EventArgs e)
        {
            textBox2.BackColor = Color.Wheat;
            textBox2.ForeColor = Color.Black;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsNumber(e.KeyChar))
            {
                label4.Text="Enter Only Number";
                textBox1.Text="";
            }
            else
            {
                label4.Text="";
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsNumber(e.KeyChar))
            {
                label4.Text="Enter Only Number";
                textBox2.Text="";
            }
            else
            {
                label4.Text="";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Total Is  "+(Convert.ToInt32(textBox1.Text)+Convert.ToInt32(textBox2.Text)));
          
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Help;
            button2.Cursor = Cursors.SizeAll;
            textBox3.Cursor = Cursors.SizeNESW;
            checkBox1.Cursor = Cursors.AppStarting;
            //Form1.ActiveForm = Cursors.AppStarting;
          
        }
    }
}
Output:-


Tuesday 21 February 2012

How To find Square of Number Using Constructor

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SquareNumber
{
    class Program
    {
        int n;
        public void Square(int n)
        {
            Console.WriteLine(n);
            n *= n;
            Console.Write(n);
        }
        Program()//Constructor
        {
            n = 10;
            Square(n);
        }

        static void Main(string[] args)
        {
            Program cal = new Program();
            Console.ReadLine();
        }
    }

}
Output:-